私は先験的な有界長の文字列を食べるCプログラムを書こうとしている。入力は小文字で構成されていると仮定します。文字列がパリンドロムかどうかをチェックする - 私はプログラムをコンパイルするときにシャットダウンする
これはプログラミングの最初のコースの一部なので、私は経験がありません。
これは私の試みです。 CodeBlocksでビルド/実行しようとすると、プログラムはシャットダウンします。私はかなりうまくいったと思ったので残念です。
#include <stdio.h>
#define MaxLength 50
int palindrome(char *a,int size) /* checks if palindrome or not */
{
int c=0;
for(int i=0;i<size/2;i++) /* for every spot up to the middle */
{
if (*(a+i)!=*(a+size-i-1)) /* the palindrome symmetry condition */
{
c++;
}
}
if (c==0)
{
return 1; /*is palindrome*/
}
else
return 0; /*is not palindrome*/
}
int main()
{
char A[MaxLength]; /*array to contain the string*/
char *a=&A[0]; /*pointer to the array*/
int i=0; /*will count the length of the string*/
int temp;
while ((temp=getchar())!='\n' && temp != EOF) /*loop to read input into the array*/
{
A[i]=temp;
i++;
}
if (palindrome(a,i)==1)
printf("1");
else
printf("0");
return 0;
}
備考。私は今寝るつもりだから、数時間は反応しません。
コードはコンパイルされません。 –