我做了一個簡單的字典代碼,衝浪了一個小時,並且我找到了一個文件I/O代碼。但我的編譯器(我使用Microsoft Visual C++)說我的代碼(不幸的是,代碼的核心部分)是錯誤的。但我無法得到它。什麼是錯誤的,爲什麼?C文件輸入&輸出
/*
DosDic ver 1.0.0 2015-07-03
*/
#include<stdio.h>
#include<string.h>
char key = 0;
FILE *fp; //set a file pointer var
fp = fopen("dicdata.dat","r"); //open a file
int b = 0;
int trial = 0;
char result[];
char searchfor[] = fp; //save a whole list of dictionary in a var
int i;
char sb[]; //var for search in a list
int getsearchtrial(char sb[]){
for(i=0;i=strlen(sb);i++){ //how much I tried to reach to the word
switch((int)searchfor[b]-(int)sb[i]){ //are two alphabets same?
case 0 :
default : i=0;
}
b++; //keep finding in a list
trial++; //try again
}
return trial;
}
int adress;
int mainpage(){
printf("Type what you want to search : ");
scanf("%c",sb[ ]);
getsearchtrial(sb[ ]) - strlen(sb[ ]) = adress; //where the word is located in the list
for(i = adress;i = adress + 30; i++){ //print
printf("%c",searchfor[i]);
}
printf("Thank you for using DosDic ver.1.0!"); //thank you!
}
void main(){ //call all those functions
mainpage();
fclose(fp); //close list
}
//and whats wrong with this? i cant even get it, but it's not working
它有什麼問題?你的編譯器告訴你什麼?什麼是確切的錯誤/警告? – user463035818
我們需要編譯器錯誤/警告和/或預期的和實際的輸出來幫助你 – LBes