Why is it that I get a stray error \302 on every line of code

Feb 21, 2020 at 7:37am
Each time I copy code from the internet I get these errors

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// C++ Program to find smallest and largest 
// elements in singly linked list. 
#include<iostream>
#include <bits/stdc++.h> 
using namespace std; 

/* Linked list node */
struct Node { 
    int data;
    struct Node* next;
}; 
// Function that returns the largest element 
// from the linked list. 

int largestElement(struct Node* head) 
{ 
    // Declare a max variable and initialize 
// it with INT_MIN value. 
    // INT_MIN is integer type and its value     // is -32767 or less. 
    int max = INT_MIN; 

    // Check loop while head not equal to NULL 
  while (head != NULL) { 
       // If max is less then head->data then 
     // assign value of head->data to max 
      // otherwise node point to next node. 
       if (max < head->data) 
        max = head->data; 
    head = head->next; 
   } 
    return max; 
} 
// Function that returns smallest element 
// from the linked list. 

int smallestElement(struct Node* head) 
{ 
    // Declare a min variable and initialize 
    // it with INT_MAX value. 
    // INT_MAX is integer type and its value 
    // is 32767 or greater. 
    int min = INT_MAX; 
   // Check loop while head not equal to NULL 
   while (head != NULL) { 
    // If min is greater then head->data then 
       // assign value of head->data to min 
        // otherwise node point to next node. 

        if (min > head->data) 
        min = head->data; 
     head = head->next; 
    } 
    return min; 
} 
// Function that push the element in linked list. 

void push(struct Node** head, int data) 
{ 
    // Allocate dynamic memory for newNode. 
    struct Node* newNode =  
        (struct Node*)malloc(sizeof(struct Node)); 
  // Assign the data into newNode. 
   newNode->data = data; 
    // newNode->next assign the address of 
   // head node. 

    newNode->next = (*head); 
   // newNode become the headNode. 

    (*head) = newNode; 
} 
// Display linked list. 
void printList(struct Node* head) 
{ 
    while (head != NULL) { 
        printf("%d -> ", head->data); 
        head = head->next; 
    } 
    cout << "NULL" << endl; 
} 
// Driver program to test the functions 

int main() 
{ 
        // Start with empty list 
    struct Node* head = NULL; 
   // Using push() function to construct 
  // singly linked list 
    // 17->22->13->14->15 
    push(&head, 15); 
    push(&head, 14); 
   push(&head, 13); 
    push(&head, 22); 
    push(&head, 17); 
    cout << "Linked list is : " << endl; 
  // Call printList() function to display 
   // the linked list. 
    printList(head); 
    cout << "Maximum element in linked list:"; 
// Call largestElement() function to get largest 
       // element in linked list. 
    cout << largestElement(head) << endl; 
    cout << "Minimum element in linked list:"; 
  // Call smallestElement() function to get smallest 

    // element in linked list. 
    cout << smallestElement(head) << endl; 
    return 0; 
} 
Feb 21, 2020 at 7:55am
It seems that somehow most of the whitespaces at the start of the lines are replaced with this characters. There is also '\240'
Feb 21, 2020 at 9:58am
After I re-type the code myself these \302 and \240 errors disappear.
Feb 21, 2020 at 11:11am
The real question that needs answering is why are you copying other people's work and especially without attribution?
Feb 21, 2020 at 5:43pm
It's what happens whenever you copy from some page that favours presentation over accuracy, by using things like "” rather than "".

The former being Unicode &#8220; and &#8221; whereas the latter are good old ASCII.

> After I re-type the code myself these \302 and \240 errors disappear.
That's probably a good idea - at least you might think about things a bit more as you're going along.

You'll also get to recognise all the common typo-induced compiler errors and know how to fix them.

Feb 21, 2020 at 8:52pm
If you use Visual Studio, it should tell you when it recognizes characters that may be of an unwanted type and offers to reformat for you.
Feb 21, 2020 at 9:01pm
Microsoft email, text editors like word, and web pages will all modify your data when you paste into them, breaking the code. I absolutely hate the modern way of screwing stuff up behind your back without telling you that so many progams build in, but that is the world we live in today. Notepad++ can fix this kind of thing as it has advanced search and replace powers and macros.
Feb 22, 2020 at 8:33am
Thank you to all!!!
I basically had to re-type the whole program before it compiled and ran OKAY!!!
Topic archived. No new replies allowed.