prob with fopen

This is a discussion on prob with fopen within the C Programming forums, part of the General Programming Boards category; here si my code #include <stdlib.h> #include <stdio.h> #include <string.h> int main() { int mode=0,readletter; char artist[48],filename; FILE *fopen(),*fptr; while(mode ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    21

    Question prob with fopen

    here si my code


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

    int main()
    {
    int mode=0,readletter;
    char artist[48],filename;
    FILE *fopen(),*fptr;


    while(mode != 5)
    {
    printf("The following options are available:\n");
    printf("\n");
    printf(" [1] Read in data\n");
    printf(" [2] Sort data\n");
    printf(" [3] Print out catalouge to screen\n");
    printf(" [4] Save data to file\n");
    printf(" [5] Exit Program\n");
    printf("\n");
    printf("Enter your choice now: ");

    scanf("%d",&mode);
    printf("\n");

    switch(mode)
    {
    case 1: /*Reading in data*/

    //printf("Enter the filename to be opened: ");
    //scanf("%s",&filename);

    if((fptr=fopen("test.txt","r"))==NULL)
    {
    printf("Error: File could not be opened\n"); //add %s so shows file name
    exit(1);
    }

    while((readletter=getc(fptr)) != EOF)
    {
    putchar(readletter);
    }

    putchar('\n');
    fclose(fptr);

    break;

    case 2:
    printf("test print2\n");
    break;

    case 3:
    printf("test print3\n");
    break;

    case 4:
    printf("test print4\n");
    break;

    case 5:
    printf("test print5\n");
    break;

    default :
    printf("Error: The option entered is not available.\n\n");
    }
    }
    }





    my prob is in case 1

    when i try if((fptr=fopen("test.txt","r"))==NULL)

    i get an error saying 'fopen' : function does not take 2 parameters

    can someone tell me what is wrong as i thought it did take 2 para
    the filename and mode string

    thx

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Code:
    int main() 
    { 
    int mode=0,readletter; 
    char artist[48],filename; 
    FILE *fopen(),*fptr; 
    
    change to

    Code:
    int mode=0,readletter; 
    char artist[48],filename; 
    FILE *fptr; 
    
    That should solve that problem, I havent looked at the rest of the code though.....

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    21

    Talking thx

    yep that was it

    i knew that bit of the code was ok

    cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 06:53 PM
  2. help with stat() and fopen()
    By movl0x1 in forum C Programming
    Replies: 6
    Last Post: 07-25-2007, 05:28 AM
  3. problem with fopen command
    By emon in forum C Programming
    Replies: 2
    Last Post: 03-11-2004, 11:11 PM
  4. wierd fopen prob
    By winterflood_j in forum C Programming
    Replies: 10
    Last Post: 02-24-2004, 05:31 AM
  5. fopen() and open()
    By Encrypted in forum C Programming
    Replies: 8
    Last Post: 02-09-2003, 03:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21