Thread: Having problems with "stray '/nnn' in program" error. Can someone help?

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    3

    Having problems with "stray '/nnn' in program" error. Can someone help?

    Hi! First of, I am completely new to C (and programming in general), so there might be some paramount error that I haven't noticed.

    Ok, so I am going through the 'Learn C the Hard Way' (because no other tutorial have been so good before), and I have encountered a problem with trying to write a string (or char array).

    Code:

    Code:
    # include <stdio.h>
    
    int main() {
    
    char full_name[] = "William Lastname";
    
    printf("My full name is: %s", full_name);
    return 0;
    
    }
    I am running Ubuntu in a VirtualBox, and using nano to write the program. When I try to make (compile?) the program, I get the following errors: "test.c:5:1: Error: Stray /302 in program" and "test.c:5:1: Error: Stray /240 in program", and in Terminal, the error points to the first c in the 'char'.

    I did some research and found out that the stray error is due to non-standard ASCII characters and most likely due to the wrong kind of quotation marks and that this was most likely due to having copying/pasted the code from one area to another, but as previously stated, I am using nano in Ubuntu so I don't really see where the problem might have originated.

    Can someone help me figure out how to fix the problem?
    Last edited by gCatnip; 04-11-2016 at 03:38 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It does not look like the usual quotes arising from say, trying to code in a rich text editor. Suppose you copied and pasted this instead:
    Code:
    #include <stdio.h>
    
    int main(void) {
        char full_name[] = "William Lastname";
        printf("My full name is: %s\n", full_name);
        return 0;
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2016
    Posts
    3
    Hmm, that's weird. It worked, thanks!
    I am still wondering what could be wrong with me code, though. Could it be because I am using a Norwegian keyboard and that they perhaps are not using standard quotation marks?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Maybe, but when installing the OS there should have been a keyboard check.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2016
    Posts
    3
    Okay, so I tried to make another program dealing only with integers to see if the problem still persists. It did not.

    Code:
    #include <stdio.h>
    
    int main() {
    
    int a = 5;
    printf("num: %d", a);
    return 0;
    
    }
    That code throws no error at all, even though I've used the exact same quotation marks. I tried with other types as well, but this seems to only be a problem with chars. :/

    EDIT: I rewrote the program the exact same way, and this time it did not throw any errors. So... I figured it out?
    Last edited by gCatnip; 04-11-2016 at 04:01 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Stray Character" when running a simple encryption program.
    By manasij7479 in forum C++ Programming
    Replies: 2
    Last Post: 08-06-2011, 09:20 AM
  2. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  3. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM
  4. "Chat" Program Problems
    By Smoose77 in forum C# Programming
    Replies: 0
    Last Post: 07-12-2002, 04:34 PM
  5. "Stray pointer" question
    By CppNewbie in forum C++ Programming
    Replies: 1
    Last Post: 01-29-2002, 01:39 PM