LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-31-2010, 03:28 PM   #1
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 899

Rep: Reputation: 70
Talking 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.
 
Old 07-31-2010, 03:44 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Start with this change:

Code:
int main()
{
    int loopcount;
    int userid=1;

    FILE *users; 
...
 
Old 07-31-2010, 04:03 PM   #3
tommylovell
Member
 
Registered: Nov 2005
Distribution: Raspbian, Debian, Ubuntu
Posts: 380

Rep: Reputation: 103Reputation: 103
Certainly not a professional programmer, but

1) the exit function requires that you include stdlib.h

#include <stdlib.h>

2) move the two variables after the opening '{' or before the 'int main()'

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h> 

int main()
{
int loopcount;
int userid=1;
.
.
.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h> 
int loopcount;
int userid=1;

int main()
{
.
.
.
 
Old 07-31-2010, 04:15 PM   #4
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 899

Original Poster
Rep: Reputation: 70
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.
 
Old 07-31-2010, 04:28 PM   #5
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 899

Original Poster
Rep: Reputation: 70
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.
 
Old 08-02-2010, 05:42 AM   #6
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 551

Rep: Reputation: 38
and misspellt userid

fprintf (target, "%useridd");
 
Old 08-02-2010, 06:10 AM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Completely Clueless View Post
... the final warning about the exit() function is still there. ...
How about

man 3 exit

?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Good linux chinese language language program? darsunt Linux - Software 1 04-10-2009 12:06 PM
short program in Python to load a page kezialounel Programming 3 03-22-2009 03:20 AM
Try to compile this short, amazing program! cryincold Programming 3 11-01-2007 12:42 PM
Program Language Sifvion Programming 7 06-06-2002 01:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration