代码中的奇怪错误

时间:2017-06-19 08:57:22

标签: c compiler-errors compilation syntax-error

我的代码

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

int main(){
    char *str, c;
    int x = 0, y = 1;

    str = (char*)malloc(sizeof(char));

    printf("Inserisci stringa principale : ");

        while (c != '\n') {
        // read the input from keyboard standard input
        c = getc(stdin);

        // re-allocate (resize) memory for character read to be stored
        str = (char*)realloc(str, y * sizeof(char));

        // store read character by making pointer point to c
        str[x] = c;

        x++;
        y++;
        }

    str[x] = '\0'; // at the end append null character to mark end of string

    printf("\nLa stringa inserita : %s", str);

      char *sub, b;
      int w = 0, z = 1;

      sub = (char*)malloc(sizeof(char));

      printf("Immetti sottostringa da cercare : ");

          while (b != '\n') {
            // read the input from keyboard standard input
            b = getc(stdin);

            // re-allocate (resize) memory for character read to be stored
            sub = (char*)realloc(sub, z * sizeof(char));

            // store read character by making pointer point to c
            sub[w] = b;

            w++;
            z++;
          }

      sub[w] = '\0'; // at the end append null character to mark end of string

    char *p1, *p2, *p3;
    int i=0,j=0,flag=0, occurrences=0;

      p1 = str;
      p2 = sub;

      for(i = 0+1; i<strlen(str); i++)
      {
        if(*p1 == *p2)
          {
              p3 = p1;


              for(j = 0;j<strlen(sub);j++)
              {
                if(*p3 == *p2)
                {
                  p3++;p2++;
                } 
                else
                  break;
              }
              p2 = sub;
              if(j + 1 == strlen(sub))
              {
                 flag = 1;
                 occurrences = occurrences + 1;
                printf("\nnel numero di volte : %d\n",occurrences );
                printf("\nSottostringa trovata all'indice : %d\n",i );
              }

          }
        p1++; 
      }


      if(flag==0)
      {
           printf("Sottostringa non trovata");
      }
    free(str);
    free(sub);
    return (0);
    }

我在尝试编译时收到此错误

> myfile.h:1: error: stray '\239' in program
> myfile.h:1: error: stray '\187' in program
> myfile.h:1: error: stray '\191' in program

我试图找到一个解决方案,但我不知道这是什么,这个错误

我尝试编译很多次,并且我收到此错误,我不知道为什么

1 个答案:

答案 0 :(得分:4)

字节序列<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="root"></div>239187UTF-8 Byte Order Mark (BOM)

您没有使用纯文本编辑器,或者要求您的编辑器使用带有BOM的UTF-8进行保存。不要这样做。另存为纯文本