Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        5年前关闭。
                                                                                            
                
        
我试图从数组中提取特定的数字。基本上我得到的文件是这样的:

阵数:13 10

长度:4

我所做的是逐个字符读取文件并将其存储在数组中。我不知道如何从数组中提取数字。这是我的代码:

int main()
{
  char ar_ch[200];
  int i = 0;
  char ch;
  FILE* file = fopen("array.txt","r");
  if(file == NULL)
  {
    perror("Error while opening the file.\n");
    exit(EXIT_FAILURE);
  }
  while((ch = fgetc(file)) != EOF)
  {
    ar_ch[i]=ch;
    i++;
  }
  ar_ch[i]='\0';
  return 0;
}

最佳答案

正确填写ar_ch后,循环遍历ar_ch并测试每个值。使用isdigit()isalpha()之类的函数(请注意,这些函数采用int值,而不是char值)来测试值的类型并根据需要进行处理。

07-28 02:04
查看更多