printing strings (was similar problem)

This is a discussion on printing strings (was similar problem) within the C Programming forums, part of the General Programming Boards category; Hey... I am having a related problem - perhaps someone could help. I'm sure it's really easy. I'm using: Code: ...

  1. #1
    Cereal Killer
    Join Date
    Jun 2004
    Posts
    8

    printing strings (was similar problem)

    Hey...

    I am having a related problem - perhaps someone could help. I'm sure it's really easy.

    I'm using:

    Code:
    char *sp_filename = "C:\\Program Files\\Dev-Cpp\\Examples\\example.out";
    
    printf("Attempting to open %c\n",*sp_filename);
    
    fp = fopen(sp_filename,"r");
        
         if(fp == NULL) {
            perror("Cannot open file");
            exit(EXIT_FAILURE);
        }
    which doesn't seem to work - all I get is:

    Attempting to open C
    Cannot open file: No such file or directory
    How do I make it take the whole string, and not just the first letter? I've tried various things like setting sp_filename[BUFSIZ] etc.

    What am I doing wrong?

    Thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > printf("Attempting to open %c\n",*sp_filename);
    Use
    printf("Attempting to open %s\n",sp_filename);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Cereal Killer
    Join Date
    Jun 2004
    Posts
    8
    Yeh, I already figured that out... Though it still didn't want to open the file, due to what I expect was the space in Program Files (since putting the file somewhere else works fine).

  4. #4
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    that's strange that a space in the directory would screw things up, but i suspect you're on windows 98 or maybe 95? it works fine for me on win2kpro... something about number of characters supported and stuff on the file system, maybe it's even just the file system, i've got ntfs and i'm guessing you're on fat32...

  5. #5
    Cereal Killer
    Join Date
    Jun 2004
    Posts
    8
    Nope... Win XP over here...

  6. #6
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    how about your file system? is it fat32? if i remember correctly windows xp by DEFAULT wants to set up fat32 but you can change it to ntfs whenever you want... that's my final guess, otherwise i don't know what would cause that. if you wanna change to ntfs by the way and you don't already know which you probably do, command line type in "convert c:\ /fs:ntfs" and c is the name of the drive you wanna convert... i might guess that would do the trick if you're willing to switch to ntfs, but that's up to your personal preference and really this is another topic so i'll shut up now...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem sorting an array of strings
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 05-07-2008, 10:02 PM
  2. problem printing string
    By gkoenig in forum C Programming
    Replies: 4
    Last Post: 05-04-2008, 11:01 PM
  3. Homework HELP - Problem Printing to file
    By brentshreve in forum C Programming
    Replies: 5
    Last Post: 04-23-2005, 03:11 AM
  4. Problem Printing
    By LuckY in forum Windows Programming
    Replies: 7
    Last Post: 01-20-2003, 05:01 PM
  5. problem with an array of strings in C
    By ornamatica in forum C Programming
    Replies: 14
    Last Post: 05-01-2002, 07:08 PM

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