what is the difference between thank you for you help
Code:char name[50],a ; scanf("%s",name); scanf("%s",name[i]); // why is this syntex invalid gets(name); name[a]=getch(); //what is this mean iam i getting a string or array?
This is a discussion on easyquestion within the C Programming forums, part of the General Programming Boards category; what is the difference between thank you for you help Code: char name[50],a ; scanf("%s",name); scanf("%s",name[i]); // why is this ...
what is the difference between thank you for you help
Code:char name[50],a ; scanf("%s",name); scanf("%s",name[i]); // why is this syntex invalid gets(name); name[a]=getch(); //what is this mean iam i getting a string or array?
Last edited by mouse666666; 02-07-2010 at 01:18 AM.
scanf is looking for a string not an array of char. meow.Code:scanf("%s",name[i]); // why is this syntex invalid
if i understand you correctlyCode:name[a]=getch(); // how do i show the value the i have imput to the user in the screen.
should work.Code:printf("%s",name);
>>scanf("%s",name);
Reads a string from the user into the array name (correct). Unsafe. Read SourceForge.net: Scanf woes - cpwiki
>>scanf("%s",name[i])
Incorrect. Tries to read a string from the user into a char whose value has been converted into an address. Double wrong. Plus "i" isn't declared anywhere. Scanf needs a pointer to a buffer where it needs to store the data. A char is not a pointer.
>>gets(name);
Worst thing to do. Ever. Read SourceForge.net: Gets - cpwiki
Furthermore, "a" is a char, yet you use it as an index. Is this intentional? Usually, an integer is used for such purposes, since, by definition, an array contains n elements of integer nature.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
this sysntax does workscanf("%s",name[i])
No, because name is a pointer to a char array, which is where you would put a string (%s). name[i] would be an element of name, which would be where you would place a single letter (%c).
Since i is totally undefined, I am guessing you are cutting and pasting code. This may seem like a clever idea, but it is actually the least effective way to figure something out. If there were absolutely no documentation or way for you to read about and learn C syntax, then you would be left throwing darts blindfolded by cutting and pasting experimentation. But fortunately there is lots and lots of tutorials, etc, etc, around, so you don't have to do that.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge