関数を使った文字列の比較
Posted: 2012年11月10日(土) 12:13
文字列を表す char型の配列a と b を受け取り、その2つの文字列が同じ文字列であれば1を返し、違う文字列であれば0を返す関数 を作りたいのですが、コンパイルするとエラーが出てしまいます。
以下が僕の作ってみたプログラムです。
これをデバッグしてみたら、
「
Debug Error!
Program: ...cumens\visual studio
2010\Projects\ex4-3.c\Debug\ex4-3.c.exe
Module: ...cuments\cisual studio
2010\Projects\ex4-3.c\Debug\ex4-3.c.exe
File:
Run - Time Checked Failure #3 - The variable 'i' is being used without being initialized.
(Press Retry to debug the application)
」
とでてきてしまいます。
このプログラムに何かおかしいところがあるということでしょうか?
おかしなところがあれば教えていただきたいです。
現在の環境は以下のとおりです
OS:Windows 7 Home Premium
コンパイラ:Microsoft Visual C++ 2010 Express
よろしくお願いします。
以下が僕の作ってみたプログラムです。
#include <stdio.h>
int equal(char a[],char b[])
{
int i;
while(a[i]!=0)
{
if(a[i]!=b[i])
{
return(0);
}
i=i+1;
}
return(1);
}
int main (void)
{
int answer;
answer=equal("hello","ohayou");
if(answer==1){
printf("correct\n");
}
else{
printf("miss\n");
}
return(0);
}
「
Debug Error!
Program: ...cumens\visual studio
2010\Projects\ex4-3.c\Debug\ex4-3.c.exe
Module: ...cuments\cisual studio
2010\Projects\ex4-3.c\Debug\ex4-3.c.exe
File:
Run - Time Checked Failure #3 - The variable 'i' is being used without being initialized.
(Press Retry to debug the application)
」
とでてきてしまいます。
このプログラムに何かおかしいところがあるということでしょうか?
おかしなところがあれば教えていただきたいです。
現在の環境は以下のとおりです
OS:Windows 7 Home Premium
コンパイラ:Microsoft Visual C++ 2010 Express
よろしくお願いします。