Thread: convert array type ??

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    10

    convert array type ??

    Hello every body
    how i can convert array type :
    char f[12] ;
    to the follwoing type :
    char *f ;

    because i want to use string saved in f[12] in the follwoing instruction :

    fopen(char *f,mode)

    Thaaaaaaaanks
    Nada

  2. #2
    Unregistered
    Guest
    When passing an array to a function, either array notation or pointer notation can be used

    void function(char *f);
    void function(char f[]);

    are the same, but only in the context of function calls.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    10
    Thanks for reply
    i try the code it doesn't work

  4. #4
    Unregistered
    Guest
    It should give you an error or a warning then, if it does then post that. I'm not sure, but I think fopen may require a string constant, not an array. That could also be the problem, the only calls to fopen that I've seen have looked like this:
    Code:
    FILE *f;
    f = fopen("filename.ext", "r");

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    10
    Hello ,
    Thank you .Your code is correct

    FILE *f;
    f = fopen("filename.ext", "r");

    but my problem is : i need fopen not only work with filename.txt .What i need is at run time fopen take filenames automtically from text file or from certain directry then deal with it

    therefore , when i write :

    char fileName[20] ;
    fopen(fileName,"r");
    at compilation there is no problem
    but at run time i get :
    segmantation fault .WHY !!!!!!

    Pleeease i need support

  6. #6
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    That should be fine.

    Segmentation fault could really mean just about anything when it comes to problems in your program.

    Is fileName null terminated? Try doing something like this:

    Code:
    #define DEBUG_PRINT { \
            printf("I'm still working...\n"); \
            fflush(stdout); }
    and pepper DEBUG_PRINT inside the main function. The error will be right after the last DEBUG_PRINT that shows and the next DEBUG_PRINT in the source. Scatter inside other functions as needed.

    BTW, fflush(stdout) might not be in <stdin.h> depending on the system, you can eliminate it in that case, it should still work OK.
    .sect signature

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  3. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM