![]() |
| | #1 |
| Registered User Join Date: Jan 2009
Posts: 13
| Code: #include<conio.h>
#include<stdio.h>
#include<stdlib.h>
char name[25];
void input_name()
{
printf("please enter your name.");
scanf("s%",&name);
}
void process()
{
for (name; <10; name+1)
printf("Your name is %s/n",name);
}
int main()
{
input_name();
process();
getch();
return 1;
}
|
| Chalmers86 is offline | |
| | #2 |
| Resu Deretsiger Join Date: Nov 2008 Location: /dev/null
Posts: 185
| Code: void process()
{
for (name; <10; name+1)
printf("Your name is %s/n",name);
}
First off . . . for (name; <10; name+1) is incorrect. Try for (; name<10; name++) instead. Now, printf("Your name is %s/n",name); again, has a bit of a problem. I'll let you find it, but one tip: /. Also, what's that return 1; doing there? ![]() Remember that bash is the opposite of C: 0 is true, successful, and !0 is false, unsuccessful. Just to confuse you some more. :P EDIT: A-whoops-a-dasies. Didn't notice the double post. My apologies.
__________________ Do as I say, not as I do . . . Experimentation is the essence of programming. Just remember to make a backup first. "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF Questions posted by these guidelines are more likely to be answered. Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator. Last edited by Nightowl; 03-22-2009 at 09:03 PM. |
| Nightowl is offline | |
| | #3 |
| CSharpener Join Date: Oct 2006
Posts: 5,242
| scanf("s%",&name); - & should be removed. Using global variables is not recomanded - pass parameters by pointer to prevent buffer overrun - add width modifier to the format Code: char name[25];
scanf("%24s", name);
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
| vart is offline | |
| | #4 |
| Registered User Join Date: Mar 2009
Posts: 8
| Code: void process()
{
int i;
for (i = 0; i<10; i++)
printf("Your name is %s\n",name);
}
Another tip: refrain from using scanf(), it is particularly unsafe, try entering in a string that is more then 25 characters long and you will see. A safer alternative is fgets() (which I believe is deprecated now) or even perhaps getline(&buffer, &length, stdin); Don't use fixed size arrays on the second one because it will spit out an error if you enter a string more then the array size. |
| hawaiian robots is offline | |
| | #5 | |||
| CSharpener Join Date: Oct 2006
Posts: 5,242
| Quote:
Quote:
Quote:
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. | |||
| vart is offline | |
![]() |
| Tags |
| problem |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| For Loop Disaster | Chalmers86 | C Programming | 3 | 03-22-2009 05:20 PM |
| Tsunami disaster. | anonytmouse | A Brief History of Cprogramming.com | 23 | 01-09-2005 09:56 AM |
| NTFS disaster recovery | -=SoKrA=- | Tech Board | 20 | 04-17-2004 02:16 AM |
| Class + Union + Struct = Disaster?? | Inquirer | C++ Programming | 5 | 10-28-2002 03:55 PM |
| disaster relief | iain | A Brief History of Cprogramming.com | 1 | 09-13-2001 08:12 PM |