Results 1 to 3 of 3

Thread: Writing to Files in C

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    England
    Posts
    312

    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

  2. #2
    Megatron
    Guest
    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;

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Also change

    #include "stdio.h"

    to

    #include <stdio.h>

    because it is a system header.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width