-1

I used Notepad++ to write the code, and when I tried to compile it (I used cc lab7.c -o test1 to compile it) I got a bunch of stray \342, stray \200, stray \234 errors, as is seen below.

Here is my code:

#include <stdio.h>
#include <string.h>


char inbase, dummy, outbase;
char response;
int inputNum;
char bin [32];

int main(void)
{
    // Perform for yes response
    while (response == 'y' || response == 'Y')
    {
        // Prompt to read in char for base of input
        printf("Enter a base to read in (b for binary, d for decimal,\n h for hexidecimal, or o for octal: ");
        scanf("%c", &inbase);

        // If binary is inbase
        if (inbase == 'b' || inbase == 'B')
        {
            printf("Enter a binary number to read: ");
            scanf("%c", &dummy);
            scanf("%s", bin);
            inputNum = binary(bin);
        }

        // If inbase is anything else, read
        else
        {
            printf("Enter an integer to read: ");
            scanf("%c", &dummy);
            scanf("%i", &inputNum);
        }

        // Output the number

        printf("Enter a base to output as: ");
        scanf("%c", &dummy);
        scanf("%c", &outbase);

        // decimal output
        if (outbase == 'd' || outbase == 'D')
        {
            printf("The integer %i in decimal is %d" inputNum, inputNum);
        }

        // hexidecimal output
        if (outbase == 'h' || outbase == 'H')
        {
            printf("The integer %i in hexidecimal is %h" inputNum, inputNum);
        }

        // octal output
        if (outbase == 'o' || outbase == 'O')
        {
            printf("The integer %i in octal is %o" inputNum, inputNum);
        }

        // check to see if user wants to run again
        printf(“Do you want to …”);
        scanf(“%c”, &dummy);
        scanf(“%c”, &response);
        scanf(“%c”, &dummy);
    }

    int binary(char* inString)
    {
        int sum=0;
        int i;

        for (i=0; i < strlen(inString); i++)
        {
            sum = sum * 2 + (inString[i] - 48);
        }

        return sum;
    }

    return 0;
}

// END OF CODE

And here are the error messages I'm getting:

lab7.c: In function ‘main’:

lab7.c:58:45: error: expected ‘)’ before ‘inputNum’
printf("The integer %i in decimal is %d" inputNum, inputNum);
                                         ^

lab7.c:64:49: error: expected ‘)’ before ‘inputNum’
printf("The integer %i in hexidecimal is %h" inputNum, inputNum);
                                             ^

lab7.c:70:43: error: expected ‘)’ before ‘inputNum’
printf("The integer %i in octal is %o" inputNum, inputNum);
                                       ^

lab7.c:74:3: error: stray ‘\342’ in program
printf(“Do you want to …”);
^

lab7.c:74:3: error: stray ‘\200’ in program

lab7.c:74:3: error: stray ‘\234’ in program

lab7.c:74:14: error: ‘Do’ undeclared (first use in this function)
printf(“Do you want to …”);
         ^

lab7.c:74:14: note: each undeclared identifier is reported only once for                    each function it appears in

lab7.c:74:17: error: expected ‘)’ before ‘you’
printf(“Do you want to …”);
            ^

lab7.c:74:17: error: stray ‘\342’ in program

lab7.c:74:17: error: stray ‘\200’ in program

lab7.c:74:17: error: stray ‘\246’ in program

lab7.c:74:17: error: stray ‘\342’ in program

lab7.c:74:17: error: stray ‘\200’ in program

lab7.c:74:17: error: stray ‘\235’ in program

lab7.c:75:3: error: stray ‘\342’ in program
scanf(“%c”, &dummy);
^

lab7.c:75:3: error: stray ‘\200’ in program

lab7.c:75:3: error: stray ‘\234’ in program

lab7.c:75:13: error: expected expression before ‘%’ token
scanf(“%c”, &dummy);
         ^

lab7.c:75:13: error: stray ‘\342’ in program

lab7.c:75:13: error: stray ‘\200’ in program

lab7.c:75:13: error: stray ‘\235’ in program

lab7.c:76:3: error: stray ‘\342’ in program
scanf(“%c”, &response);
^

lab7.c:76:3: error: stray ‘\200’ in program

lab7.c:76:3: error: stray ‘\234’ in program

lab7.c:76:13: error: expected expression before ‘%’ token
scanf(“%c”, &response);
         ^

lab7.c:76:13: error: stray ‘\342’ in program

lab7.c:76:13: error: stray ‘\200’ in program

lab7.c:76:13: error: stray ‘\235’ in program

lab7.c:77:3: error: stray ‘\342’ in program
scanf(“%c”, &dummy);
^

lab7.c:77:3: error: stray ‘\200’ in program

lab7.c:77:3: error: stray ‘\234’ in program

lab7.c:77:13: error: expected expression before ‘%’ token
scanf(“%c”, &dummy);
         ^

lab7.c:77:13: error: stray ‘\342’ in program

lab7.c:77:13: error: stray ‘\200’ in program

lab7.c:77:13: error: stray ‘\235’ in program
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
teddymv
  • 49
  • 1
  • 9
  • I made the changes duskwuff suggested and changed char response; to char response = 'y'; and it works. Thanks! – teddymv Apr 07 '17 at 01:56
  • For what is included in the title, a much more direct analysis is 226 128 156 (octal) → 0xE2 0x80 0x9C (hexadecimal) → 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:40
  • Correction: 342 200 234 (octal) - those numbers (226 128 156) are the corresponding decimal numbers. – Peter Mortensen Apr 26 '23 at 23:38

1 Answers1

1

There are a couple of issues with your code:

lab7.c:58:45: error: expected ‘)’ before ‘inputNum’
printf("The integer %i in decimal is %d" inputNum, inputNum);
                                         ^

You are missing a comma right before the indicated location, and in several similar lines which follow.

printf (“Do you want to …”);
        ^                ^

The quotation marks in the locations I've indicated are both "smart quotes" (“/”), not normal quotation marks. Retype them.

The same issue applies to each of the following errors regarding “%c”.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Thanks, I replaced those and got rid of most of them. The only ones left are these now: /tmp/ccvLZ92d.o: In function `main': lab7.c:(.text+0x84): undefined reference to `binary' collect2: error: ld returned 1 exit status – teddymv Apr 07 '17 at 01:30
  • Read my answer again. The pattern from the first answer applies to more than one line in your code. –  Apr 07 '17 at 01:32
  • Sorry, yea I edited it again. Got rid of those but then got a new error – teddymv Apr 07 '17 at 01:34
  • I took the binary method and put it below the main method, and it compiled. But it doesn't run at all when i type a.out... – teddymv Apr 07 '17 at 01:37
  • You're compiling the executable as `test1`, not `a.out`. –  Apr 07 '17 at 01:37
  • Sorry, I should've specified. The last time I compiled it, I just did cc lab7.c, not cc lab7.c -o test1. I tried both, and both just don't do anything. I'm using PuTTy, if that matters. – teddymv Apr 07 '17 at 01:39
  • I changed char response; to char response = 'y'; and that seemed to fix it. Running correctly now. – teddymv Apr 07 '17 at 01:55
  • This isn't a need to retype anything. Search with regular expression `\x{201C}|\x{201D}` (that's for [LEFT DOUBLE QUOTATION MARK](https://www.charset.org/utf-8/9) and [RIGHT DOUBLE QUOTATION MARK](https://www.charset.org/utf-8/9), respectively) and replace with "`"`" – Peter Mortensen Apr 26 '23 at 00:48
  • Note: The notation is different in Visual Studio Code (and probably others): `\u201C|\u201D` – Peter Mortensen Apr 27 '23 at 13:16