我已经重写了我以前的程序,我想将 *dirty 更改为 **dirty。你能给我一些建议吗?这是我的代码:
void clean(char *dirty)
{
int i = 0, j = 0;
char *temp;
temp = strdup(dirty);
if(NULL == temp)
{
printf("strdup(), failed");
return;
}
while(i < strlen(temp))
{
if(isalpha(temp[i]) || isspace(temp[i]) || temp[i] == '?'
|| temp[i] == '.' || temp[i] == '!' || temp[i] == ',')
{
dirty[j] = temp[i];
j++;
}
i++;
}
dirty[j] = '\0';
free(temp);
}
更改 main() 的一部分,我遇到了一些问题,和我的朋友一起,我们创建了这个:
int main(int argc, char** argv)
{
FILE* fp;
char** tab;
int i = 0;
int lines = 0;
int length = 10;
if(argc != 2)
{
printf("Incorrent syntax! Use ./name_of_program input_file\n");
return 1;
}
if(!(fp = fopen(argv[1],"r")))
{
printf("Could not open the file! Please try again!\n");
return 2;
}
tab = (char**)malloc(length*(sizeof(char*)));
if(!tab)
{
printf("Could not allocate memory!\n");
free(tab);
return 3;
}
while(!feof(fp))
{
tab[i] = getNumber(fp);
if(i >= length)
{
length += 10;
tab = (char**)realloc(tab, sizeof(char*));
if(tab == NULL)
{
free(tab);
return 5;
}
}
if(tab[i] == NULL)
{
printf("Incorrect character in the infile! Terminating\n");
free(tab);
return 4;
...