-2

My code:

    const int timer = 8;
    const int dager = 5;
    const float måned = 4.33;
    const int uker = 52;

    printf("forste persons navn: ");
    scanf("%s", navn1);

    printf("Andre persons navn: ");
    scanf("%s", navn2);

    printf("timelonn til forste person: %i");
    scanf("%i", timelonn1);

    printf("antall uker ferie til forste person: %i");
    scanf("%i", ukeferie1);

    printf("timelonn til andre person: %i");
    scanf("%i", timelonn2);

    printf("antall uker ferie til andre person: %i");
    scanf("%i", ukeferie2);

    return 0;
}

Errors I am getting:

error: stray '\345' in program

error: expected "=", ',',', 'asm' or '_attribute_'before 'ned'

error: 'ned' undeclared (first use in this functon)
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 3
    `måned` - has some weird character that shouldn't be there. – Eugene Sh. Sep 16 '22 at 20:11
  • 1
    Keep non-ascii characters out of your variables names. Just use A-Z, a-z, 0-9, and _ (underscore). – Tom Karzes Sep 16 '22 at 20:13
  • Aside: don't use `%i` as a `scanf` format spec unless the user is expected to enter octal or hexadecimal too. Use `%d` for a regular user. For example in your code an input of `012` will be decimal `10` not `12`. Also from the code fragment it isn't clear why you pass `timelonn1` to `scanf` and not `&timelonn1`, etc. – Weather Vane Sep 16 '22 at 20:32
  • From *[Why are special characters not allowed in variable names?](https://stackoverflow.com/questions/24250231/why-are-special-characters-not-allowed-in-variable-names/24252465#24252465)*: *"More modern languages (Java, C#, Scala, ...., uh, even PARLANSE) grew up in an era of Unicode, and tend to allow most of Unicode in identifiers"* – Peter Mortensen Apr 18 '23 at 17:55
  • The non-ASCII in one of the variable names suggests this is a blatant duplicate. Where is the canonical question? – Peter Mortensen Apr 18 '23 at 17:56
  • The title of your question should tell us something about the question. "_error: stray '\345' in program_" might be a good title. Omit the biographical information. You can add that to your profile page. – Clifford Apr 18 '23 at 18:27
  • What compiler are you using? C 2018 6.4.2.1 and D.1 say that various universal characters should be allowed in identifiers, including hex 00E5 (octal 345). GCC, Clang, and MSVC all accept this. – Eric Postpischil Apr 18 '23 at 18:35
  • @PeterMortensen: The C standard has allowed non-ASCII characters in identifiers since C 1999 at least. – Eric Postpischil Apr 18 '23 at 18:37
  • 1
    @EricPostpischil, yet the OP's compiler does not, so it is rather academic what the standard allows perhaps. – Clifford Apr 18 '23 at 18:53
  • @Clifford: It is not academic whether the solution is their compiler does not support it, they have had some problem in editing their source file and/or saving it in an appropriate format, or some other problem has occurred. We know the statement that “special characters” are not allowed in variable names is incorrect for C generally, and Stack Overflow is not for guessing at answers to questions. OP’s compiler ought to be determined, and the reason they got this error message ought to be determined. – Eric Postpischil Apr 18 '23 at 19:06
  • 1
    @EricPostpischil My point was that the compiler the OP is using has rejected `å` in the source. The reason for that may be use of an older compiler or explicit enforcement of an older standard, for any number of reasons error or intentional. I am not saying it is not allowed by any standard, rather explaining why it is not allowed by this compiler. It is the compiler that gets stuff done, not the standard. A long time ago, I encountered this issue in gcc 2.95 using a copyright symbol in a comment. – Clifford Apr 18 '23 at 21:12
  • 1
    ...While using a newer compiler/standard may be good advice, it is not an answer to this question. – Clifford Apr 18 '23 at 21:16
  • @Eric Postpischil: I didn't claim it wasn't allowed (on contrary. It being allowed in other C-like languages suggests there is nothing inherently blocking it). I am only interested in the canonical question. This question was posted in 2022. It must have been asked many times over in the past 14 years. – Peter Mortensen Apr 25 '23 at 22:33
  • Candidate canonical questions: *[ (and other Unicode characters) in identifiers not allowed by g++](https://stackoverflow.com/questions/12692067/)* (2012), *[What constitutes a "valid" C Identifier?](https://stackoverflow.com/questions/34319000/)* (2015), and *[Using emoji as identifier names in C++ in Visual Studio or GCC](https://stackoverflow.com/questions/30130806/)* (2015). [More candidates](https://stackoverflow.com/questions/linked/12692067?sort=votes). – Peter Mortensen Apr 25 '23 at 22:42
  • And *[Why don't these Unicode variable names work with -fextended- identifiers? «, » and ≠](https://stackoverflow.com/questions/32799078/why-dont-these-unicode-variable-names-work-with-fextended-identifiers-a)* (2015) – Peter Mortensen May 02 '23 at 18:57

2 Answers2

1

I believe your issue is here:

const int timer = 8;
const int dager = 5;
const float måned = 4.33; // This variable
const int uker = 52;

You are using characters not supported by the compiler (å).

This question seems to support that this is your issue. See the non-ASCII character used in the source code that would not compile.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JRose
  • 1,382
  • 2
  • 5
  • 18
-1

The C programming language defines a basic source character set comprising a subset of 95 ASCII characters from which source code may be composed. The character å is not one of them; for good reason (historically); it is not available in all code pages (used for regionally defined 8-bit characters), and is not available on all regional keyboards.

Essentially your code must be composed from characters universally available regardless of regionalisation and character encoding.

\345 is an octal (base 8) character code sequence used to represent characters. Here it is used in the error message because the character set used in presentation of error messages may (in a GUI IDE for example) may differ from that used in code presentation. 3458 is 229 decimal or E5 hexadecimal. In the Windows-1252 code page, that happens to be å, but is not universally true.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • [Code pages](https://en.wikipedia.org/wiki/Code_page)? Aren't we long past them? It could be [Unicode](https://en.wikipedia.org/wiki/Unicode). It is allowed in variable names in [C#](https://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29), [Scala](https://en.wikipedia.org/wiki/Scala_%28programming_language%29), [Java](https://en.wikipedia.org/wiki/Java_%28programming_language%29), etc. – Peter Mortensen Apr 18 '23 at 18:35
  • @PeterMortensen Yes, perhaps, but C is _that old_ that it _was_ a consideration when it was defined. I mention it as a historical explanation for the restrictive subset. Edited to make that more explicit. Regional keyboards remains a valid consideration of course. – Clifford Apr 18 '23 at 18:46