My code
#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
我试图找到解决方案,但我完全不知道这是什么,这个错误。
我尝试编译很多次,每次都收到这个错误。为什么?
字节序列239
, 187
and 191
is the UTF-8 字节顺序标记 (BOM) https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8.
您没有使用纯文本编辑器,或者要求您的编辑器使用带有 BOM 的 UTF-8 进行保存。不要那样做。另存为纯文本.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)