0

writing part of a program where user inputs an ID and the program generates a .txt file with the ID name(numerical ID).

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define INFILE "config.txt"
#define OUTFILE "studentans.ans"
#define IDFILE "stdin"



int main(int argc, char *argv[]) {

FILE *fout;
fout = fopen(IDFILE, "w");
printf("Enter Student ID number:");
while(1) {
getc(stdin);    // id is entered

fputs(stdin, fout);    //generates the text file
}
return 0;
}

but i keep getting these errors:
14:14 C:\Dev-Cpp\assignment 4.c [Warning] multi-character character constant
14 C:\Dev-Cpp\assignment 4.c [Warning] passing arg 1 of `fopen' makes pointer from integer without a cast
20 C:\Dev-Cpp\assignment 4.c [Warning] passing arg 1 of `fputs' makes pointer from integer without a cast


using dev-cpp but programming in C
any ideas?

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by John A
0

Your input and output methods are weird - consider something like this:

char line[255];
while(1) {
   fgets(line, 255, stdin);
   // NOTE: ideally you should validate input before printing to file

   fputs(line, fout);
}

Anyway, you can't just use stdin in place of a char *, which is what fputs expects. So of course you'll first need to retrieve the input before printing it to a file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.