C compiling / error: stray ‘\’ in program

This is a discussion on C compiling / error: stray ‘\’ in program within the C Programming forums, part of the General Programming Boards category; Dear all, I have a problem with compiling my program. I need to write to a file sequence of symbols. ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    9

    C compiling / error: stray ‘\’ in program

    Dear all,

    I have a problem with compiling my program. I need to write to a file sequence of symbols. But there is a problem with symbol "\".


    making_python_files.c:31: error: stray ‘\’ in program
    making_python_files.c:31: error: expected ‘)’ before ‘n’
    making_python_files.c:32: error: invalid operands to binary % (have ‘char *’ and ‘float’)
    making_python_files.c:32: error: expected ‘)’ before string constant
    making_python_files.c:32: warning: format not a string literal and no format arguments

    The error massages concern line with fpriptf command below.
    I will be very grateful for any advises.


    insert
    Code:
    main(void)
    {
      
      FILE *fp;
    
            fp=fopen(filename,"w");
     
    	   fprintf(fp,"print "\n".join(map(lambda x:");
    	   fprintf(fp,""%.6f %.6f %.6f %.6f %.6f %.6f" % tuple(x), molsystem.conf[molname]))");	   
       
           
           fclose(fp);
    }

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Code:
    	   fprintf(fp,"print "\n".join(map(lambda x:");
    	   fprintf(fp,""%.6f %.6f %.6f %.6f %.6f %.6f" % tuple(x), molsystem.conf[molname]))");
    Stray " in your code is marked with red.
    If you want to insert a " into a string, use \".
    And main shall return int.
    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.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    9
    Dear Elysia,

    Thanks a lot for the prompt reply. I did what you said, and it compiles now. But it does not do what I really need.
    In line below it executes \n (makes a new line) instead of typing this symbol "\n" to a file.
    insert
    Code:
    fprintf(fp,"print \"\n\"");
    It also does not print sequence %.6f %.6f %.6f %.6f %.6f %.6f properly. The program expects variables of corresponding types and writes some strange numbers instead.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Quote Originally Posted by Elya View Post
    In line below it executes \n (makes a new line) instead of typing this symbol "\n" to a file.
    insert
    Code:
    fprintf(fp,"print \"\n\"");
    I'm not sure what you mean or expect here.
    print "
    "
    Should be written to the file with the above code.

    It also does not print sequence %.6f %.6f %.6f %.6f %.6f %.6f properly. The program expects variables of corresponding types and writes some strange numbers instead.
    True, this is because you use fprintf. They are formatting stuff.
    If you need to write that to the file as a string, you can use fputs, or you can do %% to print a % to the file.
    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.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    9
    Dear Elysia,

    Thank you so much for your help! All problems solved.

    Elya

  6. #6
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    To print the following to a file:
    \n
    You need the following printf:
    Code:
    printf ("\\n");
    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  3. adding an #include stops my program from compiling
    By angelscars in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2005, 04:24 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Replies: 3
    Last Post: 04-19-2004, 08:09 AM

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