我通过 C 编译器运行了以下代码。
#include <assert.h> // Conditionally compiled macro that compares its argument to zero
#include <complex.h> // (since C99) Complex number arithmetic
#include <ctype.h> // Functions to determine the type contained in character data
#include <errno.h> // Macros reporting error conditions
#include <fenv.h> // (since C99) Floating-point environment
#include <float.h> // Limits of float types
#include <inttypes.h> // (since C99) Format conversion of integer types
#include <iso646.h> // (since C95) Alternative operator spellings
#include <limits.h> // Sizes of basic types
#include <locale.h> // Localization utilities
#include <math.h> // Common mathematics functions
#include <setjmp.h> // Nonlocal jumps
#include <signal.h> // Signal handling
#include <stdalign.h> // (since C11) alignas and alignof convenience macros
#include <stdarg.h> // Variable arguments
#include <stdatomic.h> // (since C11) Atomic types
#include <stdbool.h> // (since C99) Boolean type
#include <stddef.h> // Common macro definitions
#include <stdint.h> // (since C99) Fixed-width integer types
#include <stdio.h> // Input/output
#include <stdlib.h> // General utilities: memory management, program utilities, string conversions, random numbers
#include <stdnoreturn.h> // (since C11) noreturn convenience macros
#include <string.h> // String handling
#include <tgmath.h> // (since C99) Type-generic math (macros wrapping math.h and complex.h)
#include <time.h> // Time/date utilities
#include <uchar.h> // (since C11) UTF-16 and UTF-32 character utilities
#include <wchar.h> // (since C95) Extended multibyte and wide character utilities
#include <wctype.h> // (since C95)
int main(){
int ptr[]={0, 1, 2};
int ptr1[]={3, 4, 5};
int isFound=0;
int wordCounter=0;
int totalCounter=0;
int lineCounter=0;
int i=1;
int k=0;
while (strlen(ptr[k]) > 1 && strlen (ptr1[i]) > 1)
{
while ((strlen (ptr[k]) > 1 && strlen (ptr1[i]) > 1) && isFound == 0)
{
totalCounter++;
lineCounter++;
if (strcmp (ptr[k], ptr1[i]) == 0)
{
printf ("'%s' is word %d in the list\n", ptr[k], lineCounter);
isFound = 1;
}
k++;
}
if (isFound == 0)
{
printf ("'%s' is not in the word list\n", ptr1[i]);
}
isFound = 0;
lineCounter = 0;
k = 0;
i++;
wordCounter++;
}
}
这是我将其放入编译器时捕获的错误。
main.c:38:17:警告:传递“strlen”的参数 1 会生成指针
从没有强制转换的整数 [-Wint-conversion]
/usr/include/string.h:399:15:注意:预期为“const char *”,但
参数的类型是“int”
main.c:38:40: 警告:传递‘strlen’的参数 1 会生成指针
从没有强制转换的整数 [-Wint-conversion]
/usr/include/string.h:399:15:注意:预期为“const char *”,但
参数的类型是“int”
main.c:40:19: 警告:传递“strlen”的参数 1 会生成指针
从没有强制转换的整数 [-Wint-conversion]
/usr/include/string.h:399:15:注意:预期为“const char *”,但
参数的类型是“int”
main.c:40:42: 警告:传递“strlen”的参数 1 生成指针
从没有强制转换的整数 [-Wint-conversion]
/usr/include/string.h:399:15:注意:预期为“const char *”,但
参数的类型是“int”
main.c:44:16: 警告:传递‘strcmp’的参数 1 会生成指针
从没有强制转换的整数 [-Wint-conversion]
/usr/include/string.h:144:12:注意:预期为“const char *”,但
参数的类型是“int”
分段错误
程序以退出代码 139 结束