0

I am trying to compile a C file in the GNU/Linux operating system, but when I try to compile this code, the compiler gives me some errors.

My op.c file is this:

#include <stdio.h>

int main(int argc, char *argv[]){

    int i;
    for (i=0; i < argc; i++){
        printf(“command line argument [%d] = %s \n”, i, argv[i]);
    }

    return 0;
}

When I try to compile this code, I am getting these errors. How can I fix them?

op.c: In function ‘main’:
op.c:6:3: error: stray ‘\342’ in program
   printf(“command line argument [%d] = %s \n”, i, argv[i]);
   ^
op.c:6:3: error: stray ‘\200’ in program
op.c:6:3: error: stray ‘\234’ in program
op.c:6:13: error: ‘command’ undeclared (first use in this function)
   printf(“command line argument [%d] = %s \n”, i, argv[i]);
             ^
op.c:6:13: note: each undeclared identifier is reported only once for each function it appears in
op.c:6:21: error: expected ‘)’ before ‘line’
   printf(“command line argument [%d] = %s \n”, i, argv[i]);
                     ^
op.c:6:21: error: stray ‘\’ in program
op.c:6:21: error: stray ‘\342’ in program
op.c:6:21: error: stray ‘\200’ in program
op.c:6:21: error: stray ‘\235’ in program
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Selin Gök
  • 331
  • 1
  • 5
  • 20
  • 4
    You can't use "smart" quotes in source files. – Paul R Mar 01 '17 at 16:26
  • 1
    The first thing to do with compiler errors is not to come to Stack Overflow and ask about it, but to enter the exact error into Google search and open the first link. – Antti Haapala -- Слава Україні Mar 01 '17 at 16:28
  • 1
    These errors are coming from extended ASCII characters in the source code, which are not allowed by the syntax. –  Mar 01 '17 at 16:28
  • If you use an editor with syntax highlighting, strings using "normal" double-quotes `"` are probably having a special color. If you use your quotes then it won't have that special color. Are you perhaps not using a code-oriented text editor? Are you using a documentation editor like Microsoft Word or similar? – Some programmer dude Mar 01 '17 at 16:29
  • The real duplicate is the canonical *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Mar 06 '21 at 15:05
  • It is not only 342. It is the sequence 342 200 234. A much more direct analysis is 342 200 234 (octal) → 0xE2 0x80 0x9C → UTF-8 sequence for Unicode code point U+201C [LEFT DOUBLE QUOTATION MARK](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128). Most text editors (e.g. [Geany](https://en.wikipedia.org/wiki/Geany) (Linux and Windows) and [Notepad++](https://en.wikipedia.org/wiki/Notepad%2B%2B)) with a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) mode will be able to do search/replace for Unicode code point U+201C, using `\x{201C}`. – Peter Mortensen Mar 06 '21 at 19:50
  • 1
    @Some programmer dude: It is more likely caused by copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. Here is an account of [a school using PDF files](https://stackoverflow.com/questions/67179052/how-can-i-copy-c-code-from-a-pdf-file-to-the-codeblocks-ide) as a standard procedure for transferring code... – Peter Mortensen Apr 26 '23 at 00:35

1 Answers1

3

Use correct the quotation mark for string representation in C.

printf("command line argument [%d] = %s \n", i, argv[i]);

Instead of

printf(“command line argument [%d] = %s \n”, i, argv[i]);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
msc
  • 33,420
  • 29
  • 119
  • 214