Results 1 to 10 of 15
-
12th Feb 2012, 08:45 AM #1OPBannedWebsite's:
cityvillehelp.comTurbo 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
-
12th Feb 2012, 08:53 AM #2MemberWebsite's:
sborg.usI 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
-
12th Feb 2012, 08:55 AM #3OPBannedWebsite's:
cityvillehelp.comyes yes,,
%[^\t] means it will keep accepting text until the user enters a TAB
thanks
-
12th Feb 2012, 08:56 AM #4
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.
-
12th Feb 2012, 09:09 AM #5OPBannedWebsite's:
cityvillehelp.comPHP Code:#include<stdio.h>
#include<conio.h>
void call(int, int, int);
void main()
{
clrscr();
int a=10;
call(a,a++,++a);
getch();
}
void call(int x,int y, int 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 ???
-
12th Feb 2012, 09:10 AM #6OPBannedWebsite's:
cityvillehelp.comhere 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
-
12th Feb 2012, 12:18 PM #7MemberWebsite's:
sborg.usYou 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
-
12th Feb 2012, 01:09 PM #8MemberWebsite'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.
-
12th Feb 2012, 03:45 PM #9OPBannedWebsite's:
cityvillehelp.comhey
thanks brothers
i will surely do revision on post / pre increment & decrements
thanks a lot
rep added
-
12th Feb 2012, 03:52 PM #10OPBannedWebsite'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
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Md5 generation on Turbo C
By prateek in forum Web Development AreaReplies: 5Last Post: 14th Feb 2012, 08:42 PM -
Turbo C | Weird and amazing
By prateek in forum Web Development AreaReplies: 13Last Post: 11th Feb 2012, 04:57 PM -
Turbo C | Help Needed
By prateek in forum Web Application/Script SupportReplies: 17Last Post: 12th Jan 2012, 12:26 PM -
Turbo Leech - FREE Rapidleech Server With 8 Premium Account
By Faizann20 in forum Useful SitesReplies: 9Last Post: 2nd Dec 2010, 05:00 AM -
Looking to buy sites, in a strange way :P
By JmZ in forum Completed TransactionsReplies: 4Last Post: 15th May 2008, 02:21 AM
themaCreator - create posts from...
Version 3.17 released. Open older version (or...