Thread: error stray 342 in programm

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

    error stray 342 in programm

    Hello

    i want that the user inputs an number, wich will be printed .
    If he doesnt input a number but f.e a character, than the while shouldnt run (because it would be 0 ) and the last printf will not work.
    For some reason codeblocks is giving me an error message saying


    : /home/nantia/Desktop/A7-8960.c||In function ‘main’:|/home/nantia/Desktop/A7-8960.c|11|error: stray ‘\342’ in program|
    /home/nantia/Desktop/A7-8960.c|11|error: stray ‘\200’ in program|
    /home/nantia/Desktop/A7-8960.c|11|error: stray ‘\234’ in program|
    /home/nantia/Desktop/A7-8960.c|11|error: expected expression before ‘%’ token|
    /home/nantia/Desktop/A7-8960.c|11|error: stray ‘\342’ in program|
    /home/nantia/Desktop/A7-8960.c|11|error: stray ‘\200’ in program|
    /home/nantia/Desktop/A7-8960.c|11|error: stray ‘\235’ in program|
    ||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|




    Code:
    
    
    #include<stdio.h>
    
    
    int
    main()
    
    
    {
    
    
    int number;
    printf("please type a number");
    while (scanf(“%d”,&number)==1)
    {
    printf("you tiped the number %d",number); 
    }
    
    
    return 0;
    
    
    }

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    This usually happens when you use non-ASCII characters, here probably a bunch of characters that are similar to whitespace(or can't be printed). You need to remember to use ASCII as the file's encoding.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Apr 2016
    Posts
    16
    I went to codeblocks and edited the encoding to ASCII ,if you meant that.
    But it seems that this is not the problem.
    I still try to build it and the same error messages appear ...

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Look at the quotes in the "scanf()" call - those are "smart quotes", which your compiler does not recognize. As GReaper mentioned, there may be other stray invisible characters, as well.

  5. #5
    Registered User
    Join Date
    Apr 2016
    Posts
    16
    ok.i understood that with the quotes.
    But still dont know how to solve that problem ..

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Did you get additional errors after fixing the quote issue?

  7. #7
    Registered User
    Join Date
    Dec 2015
    Posts
    112
    in an example program you can take those characters to a char and see what value it is actually is. You can then bounce off an ascii table online to see if it is actual quotes.

  8. #8
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Anyways, when editing code remember to use a proper code editor or IDE such as notepad++ or codeblocks, that way you won't have those special characters sneaking in.

    There's no point trying to find where the characters are in the code, create a new file and copy everything manually( it isn't much ).
    Devoted my life to programming...

  9. #9
    Registered User
    Join Date
    Apr 2016
    Posts
    16
    GReaper , you were right!
    i rewrote the code in a new program by my self and everything works .
    I can not understand what the problem was, but thank you!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Glut Camera/stray error: need tutorial/advice
    By drewtoby in forum C++ Programming
    Replies: 7
    Last Post: 05-21-2011, 07:44 PM
  2. Stray Error while compiling
    By Mankthetank19 in forum C Programming
    Replies: 6
    Last Post: 02-03-2011, 03:24 PM
  3. What does: 'error: stray ‘o357’ in program' mean?
    By Phanixis in forum Linux Programming
    Replies: 8
    Last Post: 12-04-2010, 01:48 AM
  4. C compiling / error: stray ‘\’ in program
    By Elya in forum C Programming
    Replies: 5
    Last Post: 07-02-2009, 08:20 AM
  5. Simple programm error
    By datainjector in forum C Programming
    Replies: 6
    Last Post: 09-15-2002, 09:09 PM