C Language - What do these errors indicate in this short program?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
C Language - What do these errors indicate in this short program?
Hi guys,
I'm writing a short program to create single .csv files from separate data source files but have run into some trouble. I cannot understand why I am getting these errors which I am sure will be quickly spotted by a professional programmer which I am obviously not!! Clue appreciated....
Code:
cvs_maker.c: In function ‘main’:
cvs_maker.c:7: error: parameter ‘userid’ is initialized
cvs_maker.c:7: error: declaration for parameter ‘userid’ but no such parameter
cvs_maker.c:6: error: declaration for parameter ‘loopcount’ but no such parameter
cvs_maker.c:65: warning: incompatible implicit declaration of built-in function ‘exit’
The program in question is below....
Code:
#include <stdio.h>
#include <string.h>
int main()
int loopcount;
int userid=1;
{
FILE *users;
users=fopen("users.txt", "r");
if(users==NULL)
{
printf("Error: can't open file.\n");
return 1;
}
FILE *pass;
pass=fopen("pass.txt", "r");
if(pass==NULL)
{
printf("Error: can't open file.\n");
return 1;
}
FILE *target;
target=fopen("target.cvs", "w+");
if(target==NULL)
{
printf("Error: can't create target file.\n");
return 1;
}
for (loopcount=0; loopcount<70; loopcount++); {
char usr[8]; // array to store usernames
char pwd[40]; // array to store the passwords
fputs ("CSN00", target);
fprintf (target, "%useridd");
fputc (',', target);
fgets (usr, 9, users); // grabs first line of user file, inc./n
usr[8]=','; //overwrite the newline char with a comma
fputs (usr, target);
fgets(pwd, 40, pass);
fputs(pwd, target);
userid++;
}
fclose (users);
fclose (pass);
fclose (target);
exit(0);
}
Last edited by Completely Clueless; 07-31-2010 at 03:30 PM.
Thanks, Dugan. It compiles fine now, although the final warning about the exit() function is still there. Oops! Tommy has fixed that too now. Thanks, guys!
Last edited by Completely Clueless; 07-31-2010 at 04:17 PM.
Actually that is not quite right. The exit() warning message was fixed by the include <stdlib.h> preprocessor addition, but moving the variable declarations outside main() caused the gcc to give a segmentation error. But i's fine again now and thanks again.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.