#include <stdio.h>
main()
{
char* str;
char* strrev;
int i = 0;
int j = 0;
int c;
printf("Enter the string\n");
scanf("%[^\n]%*c", str);
while (*(str + i) != '\n')
{
i++;
}
for (c = i; c >= 0; c--)
{
*(strrev + j) = *(str + c);
j++;
}
}
這是我的代碼來反轉字符串。當我編譯代碼時,它會給出錯誤segmentation fault
。有人plz幫助我瞭解錯誤,並意識到我的錯誤。 感謝使用指針反轉字符串的C代碼
學會格式代碼,這有利於防止錯誤。 –
還學習調試,這將幫助您找到重新修復的錯誤。 – usr2564301