0

I'm better at C++ than C right now and I forgot how to use arrays in functions from main.
I want to do something like

void fileReader(infile[] );

. Is infile supposed to be a pointer and if so how is it written?

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Aia
0

void fileReader(infile[] );

like void fileReader( char *infile ) ???

[Edit] That's the prototype of a function that accepts a string as parameter
fileReader( string ); is the actual call in main where string could be
char string[] or char *ptr_to_string = string; or char *string = "literal string";

0

void fileReader(infile[] );

like void fileReader( char *infile ) ???

Yes that would be what I want to do. How do I declare it and use it in both the main function and the void function?

0

Yes that would be what I want to do. How do I declare it and use it in both the main function and the void function?

void fileRead( char *s );

int main( void )
{
    char *stringy = "I am a read only string";
    char str[] = "I am free to change";
    char *str_ptr = str; /* slave of str ;) */

   /* call to fileRead */
    fileRead( stringy );
    fileRead( str );
    fileRead( str_ptr );
    :
    :
    :
    return 0;
}
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.