Like Tree1Likes
  • 1 Post By Salem

warning: unknown escape sequence

This is a discussion on warning: unknown escape sequence within the C Programming forums, part of the General Programming Boards category; Hi everyone, I'm doing some file input/output work here in C and received this warning during compilation (GCC). My research ...

  1. #1
    Registered User Harvey Meale's Avatar
    Join Date
    Jan 2013
    Location
    Australia
    Posts
    4

    warning: unknown escape sequence

    Hi everyone,

    I'm doing some file input/output work here in C and received this warning during compilation (GCC). My research indicates that this error is in response to white space or a character cancellation function or something like that. I'm not 100% sure exactly what it means. I was hoping some of you could help! My code works fine, but the following warning does appear.

    Code:
    warning: unknown escape sequence: '\040'
    Here's my code (excluding a bunch of comments at the bottom of the file).

    Code:
    #include <stdio.h>
    
    
    int main(void){
        FILE *file;
        file = fopen("Running\ Practice.c", "a");
        fprintf(file, "Testing...\n");
        fclose(file);
    }
    I believe the error I received has to do with either the '\n' I used when appending text to my file, or something to do with there being a space in the file name itself.

    Any information (in lamen's terms if possible), would be greatly appreciated!

    Thanks,
    Harvey

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694

    warning: unknown escape sequence: '\040' [ANWER]

    warning: unknown escape sequence: '\040'
    Started by Harvey Meale, 4 Hours Ago
    I can't open the thread mentioned above, but I would say that I know the answer.

    This usually occurs, when you copy paste code. Check the single quotes and double quotes. Delete them and rewrite your self (only the quotes). Hope this fixes the warning.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    > file = fopen("Running\ Practice.c", "a");
    \n, \r, \t etc are valid escape sequences.
    \<space> is not a valid sequence.

    The 040 comes about because a space is ASCII decimal 32, which in octal is 040.

    If you were trying to create a pathname with a directory separator, then do this
    file = fopen("Running\\Practice.c", "a");
    iMalc likes this.
    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.

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    1,220
    Quote Originally Posted by Harvey Meale View Post
    I believe the error I received has to do with either the '\n' I used when appending text to my file, or something to do with there being a space in the file name itself.
    For spaces in filenames, you don't need any special escape character. Although giving a filename with spaces to a shell command might require this, but that's another story.

  5. #5
    Registered User Harvey Meale's Avatar
    Join Date
    Jan 2013
    Location
    Australia
    Posts
    4
    Right so, Salem, would I be able to leave it as 'Running Practice.' or do I need the double backslashes? Also, I apologize about the double post. When I posted this thread, I'd receive an error and it posted twice and I couldn't open either of these two threads. Not sure why that is.

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    1,220
    Quote Originally Posted by Harvey Meale View Post
    would I be able to leave it as 'Running Practice.' or do I need the double backslashes?
    On Windows, the \ separates path elements. So if you have a folder called "my dir" and you want to open a file inside that called "my file.txt" you might do the following:

    Code:
    FILE *fp = fopen("my dir\\my file.txt","a");
    However, Windows also accepts '/' as the separator, along with Linux, MacOS, FreeBSD, etc... so it would be better to just use this so that it works on all common systems:
    Code:
    FILE *fp = fopen("my dir/my file.txt","a");

  7. #7
    Registered User Harvey Meale's Avatar
    Join Date
    Jan 2013
    Location
    Australia
    Posts
    4
    Quote Originally Posted by c99tutorial View Post
    On Windows, the \ separates path elements. So if you have a folder called "my dir" and you want to open a file inside that called "my file.txt" you might do the following:

    Code:
    FILE *fp = fopen("my dir\\my file.txt","a");
    However, Windows also accepts '/' as the separator, along with Linux, MacOS, FreeBSD, etc... so it would be better to just use this so that it works on all common systems:
    Code:
    FILE *fp = fopen("my dir/my file.txt","a");
    Oh, okay. I'm actually using Linux and the file name is 'Running Practice.c' in the directory 'Running Practice'. I currently use the backslash in both the file name and the directory, but will try with just the directory in the future.

    Cheers!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. warning: unknown escape sequence: '\040' [ANWER]
    By std10093 in forum C Programming
    Replies: 0
    Last Post: 02-02-2013, 10:09 AM
  2. escape sequence help please
    By Shinzu911 in forum C Programming
    Replies: 1
    Last Post: 05-03-2012, 05:34 PM
  3. Replies: 4
    Last Post: 03-12-2011, 06:59 PM
  4. Replies: 9
    Last Post: 05-28-2010, 11:11 AM

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