Thread: file input and file pointer problem

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    47

    file input and file pointer problem

    I get 4 errors in this method:

    Code:
    void requestFileName(FILE **fp)
    {
    	char inputFilename[30];
    	printf("Enter the name of the file to be scanned: ");
    
    	scanf("%s", inputFilename);
    	printf("\n");	// adds a space in between file names and file statistics
    
    	*fp = fopen(inputFilename, "r");	// open the file as read-only
    }


    Code:
    Error	1	error C2143: syntax error : missing ')' before '*'	c:\users\james doyle\documents\visual studio 2005\projects\programmingassignments\programmingassignments\programmingassignment2inputoutput.c	1
    Error	2	error C2143: syntax error : missing '{' before '*'	c:\users\james doyle\documents\visual studio 2005\projects\programmingassignments\programmingassignments\programmingassignment2inputoutput.c	1
    Error	3	error C2059: syntax error : ')'	c:\users\james doyle\documents\visual studio 2005\projects\programmingassignments\programmingassignments\programmingassignment2inputoutput.c	1
    Error	4	error C2054: expected '(' to follow 'fp'	c:\users\james doyle\documents\visual studio 2005\projects\programmingassignments\programs\p2inputoutput.c	2

    I am unsure as to what is causing them. I am pretty sure all syntax is correct. If anyone knows what i did wrong, I would be very appreciative for some assistance.

  2. #2
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Have you included <stdio.h> ?
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    47
    In my project, I have a main.c file that has #include "ProgrammingAssignment2.h" and in ProgrammingAssignment2.h, I have #include <stdio.h>. When i added #include <stdio.h> to the file that I originally posted, the program worked. But I am not supposed to have include statements in this file for the assignment.

  4. #4
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    This snippet is from your main.c file or is it from another file?
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by drater View Post
    Code:
    	scanf("%s", inputFilename);
    Important:
    http://cboard.cprogramming.com/showp...37&postcount=9
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    47
    Quote Originally Posted by xuftugulus View Post
    This snippet is from your main.c file or is it from another file?
    It is a snippet from another file.

  7. #7
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by drater View Post
    It is a snippet from another file.
    This file should also include stdio.h directly or indirectly
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM