以前のプログラムを書き直したので、*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;
...