-
Writing to Files in C
Right i got this code
Code:
#include "stdafx.h"
#include "stdio.h"
int main()
{
int print1;
FILE *stream, *fopen(10);
stream = fopen("input.ini", "w");
printf("What would yo ulike to write?");
scanf("%i", print1);
fprintf("%i", &print1);
return(0);
}
as you have most probalbly guessed, i am v new at C, and am wondering why this is returning these DEBUG results
C:\My Coding Stuff\C\oepning a file\oepning a file.cpp(9) : error C2059: syntax error : 'constant'
C:\My Coding Stuff\C\oepning a file\oepning a file.cpp(11) : error C2660: 'fopen' : function does not take 2 parameters
C:\My Coding Stuff\C\oepning a file\oepning a file.cpp(14) : error C2664: 'fprintf' : cannot convert parameter 1 from 'char [3]' to 'struct _iobuf *'
thanx :D
-
Try this instead.
Code:
int print1;
FILE *stream;
stream = fopen("input.ini", "w");
printf("What would yo ulike to write?");
scanf("%d", &print1);
fprintf( stream, "%d", print1);
return 0;
-
Also change
#include "stdio.h"
to
#include <stdio.h>
because it is a system header.