Errors in code and idk what to do

Okay so here is my code that my teacher gave however whenever I run it fails, so I do not want to modify it until I can get the original to work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * echoString2.c
 * Echoes a string entered by user. Converts input
 * to C-style string.
 * Bob Plantz - 19 June 2009
 */

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

 int main(void)
{
 char aString[200];
 char *stringPtr = aString;

 write(STDOUT_FILENO, "Enter a text string: ",
 strlen("Enter a text string: ")); // prompt user

 read(STDIN_FILENO, stringPtr, 1); // get first character
 while (*stringPtr != ’\n’) // look for end of line
 {
 stringPtr++; // move to next location
 read(STDIN_FILENO, stringPtr, 1); // get next character
 }
 *stringPtr = ’\0’; // make into C string

 // now echo for user
 printf("You entered:\n%s\n", aString);

 return 0;
 }


and these are my errors


21 2 Untitled1.cpp [Error] stray '\222' in program
21 2 Untitled1.cpp [Error] stray '\' in program
21 2 Untitled1.cpp [Error] stray '\222' in program
26 2 Untitled1.cpp [Error] stray '\222' in program
26 2 Untitled1.cpp [Error] stray '\' in program
26 2 Untitled1.cpp [Error] stray '\222' in program
Untitled1.cpp In function 'int main()':
21 25 Untitled1.cpp [Error] 'n' was not declared in this scope
Look at the difference between these two quotes:
1
2
’a’ //invalid
'b' //valid 
Most likely your teacher wrote this in MS Word or similar, which formatted the code with the weird quote characters. Just retype the quotes yourself as normal quote characters.
Last edited on
Like it says, lines 21 and 26. You don't have proper single quote characters, but something that almost looks like them. Replace them.
Thank you that worked haha
Topic archived. No new replies allowed.