Activity Stream
48,167 MEMBERS
6909 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1.     
    #1
    Banned
    Website's:
    cityvillehelp.com

    Default Turbo C | scanf() | strange

    Please see the source code
    I am amazed
    the scanf function has %[^\n] it should be %s
    why this is working fine ??? what does this mean ??? ---> %[^\n] in scanf function ??

    Source Code
    PHP Code: 
    #include<stdio.h>
    #include<conio.h>
    main()
    {
        
    char str[20];
        
    clrscr();
        
    scanf("%[^\n]",str);
        
    printf("\n\n\n%s",str);
        
    getch();


    Output
    prateek Reviewed by prateek on . Turbo C | scanf() | strange Please see the source code I am amazed the scanf function has % it should be %s why this is working fine ??? what does this mean ??? ---> % in scanf function ?? Source Code #include<stdio.h> #include<conio.h> main() { Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    sborg.us
    I guess that'll scan everything till you goto a new line O.o

    ^ - Not
    \n - New line

    [^\n] - Not a new line

    V3g3ta | Halcyon | Abhi

  4.     
    #3
    Banned
    Website's:
    cityvillehelp.com
    yes yes,,

    %[^\t] means it will keep accepting text until the user enters a TAB


    thanks

  5.     
    #4
    Respected Member
    Bharat's Avatar
    Website's:
    ShineServers.Com Pickadedi.com
    If you use a trailing space (a space at the end of the format string), your program appears to hang. Instead of entering a blank line or using space characters, you must enter what the value of str2 will be. The same for str3 and when it asks for str3's value, you would enter a value that won't appear. For example, use "%[^\n] " instead of "%[^\n]"/" %[^\n]". Your newline will be ignored as specified...and eaten by the trailing space in the format string. Since scanf didn't get a '\n' character, it will want more data. str2 will have that value and str3 will have str2's value.

  6.     
    #5
    Banned
    Website's:
    cityvillehelp.com
    PHP Code: 
    #include<stdio.h>
    #include<conio.h>
    void call(intintint);
    void main()
    {
        
    clrscr();
        
    int a=10;
        
    call(a,a++,++a);
        
    getch();
    }
    void call(int x,int yint z)
    {
        
    printf("%d %d %d ",x,y,z);


    why the output is
    12 11 11

    ???
    i know post and pre increment perfectly
    but what is happening here ???

  7.     
    #6
    Banned
    Website's:
    cityvillehelp.com
    here is what I think

    first x will get the value 10,
    then y will get value 10
    then a will bcum 11
    then again a will increase and bcum 12
    then z will get 12

    but it's not happening like that
    the output is 12 11 11
    why ??




    or

    it should give 10 11 12
    as the output .. whats happning

  8.     
    #7
    Member
    Website's:
    sborg.us
    You need to brush up the post/pre increment concepts a bit

    But you also need to know that post/pre increment is machine dependent and may throw different results

    Check this link: http://codepad.org/LmpZxhgD

    V3g3ta | Halcyon | Abhi

  9.     
    #8
    Member
    Website's:
    RLGeeks.info
    [^\n] If I remeber right than this method is used to recieve a string with space through scanf().Normally you cannot do so directly in c if you do so then the string before space get accepted.

    And for that operator one first

    while calling first a++ get execute and passed i.e. z=11
    then a++ i.e. y=11
    then a i.e x=12

    Hence output is 12 11 11

    You must have a look on c function calling convention and post/pre increment function as Halcyon said.

  10.     
    #9
    Banned
    Website's:
    cityvillehelp.com
    hey
    thanks brothers

    i will surely do revision on post / pre increment & decrements

    thanks a lot


    rep added

  11.     
    #10
    Banned
    Website's:
    cityvillehelp.com
    @BJ@008

    that means
    the value is passed from right to left ? :-\
    can you plz explain a bit more


    while calling first a++ get execute and passed i.e. z=11
    then a++ i.e. y=11
    then a i.e x=12

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Md5 generation on Turbo C
    By prateek in forum Web Development Area
    Replies: 5
    Last Post: 14th Feb 2012, 08:42 PM
  2. Turbo C | Weird and amazing
    By prateek in forum Web Development Area
    Replies: 13
    Last Post: 11th Feb 2012, 04:57 PM
  3. Turbo C | Help Needed
    By prateek in forum Web Application/Script Support
    Replies: 17
    Last Post: 12th Jan 2012, 12:26 PM
  4. Replies: 9
    Last Post: 2nd Dec 2010, 05:00 AM
  5. Looking to buy sites, in a strange way :P
    By JmZ in forum Completed Transactions
    Replies: 4
    Last Post: 15th May 2008, 02:21 AM

Tags for this Thread

BE SOCIAL