函数仅返回地址而不返回字符

时间:2018-05-09 21:08:07

标签: c pointers

我的指针并不那么有才华。我的函数只返回地址而不是单词本身。

 char* randstring(){
  char words[20];
  FILE *fp;
  int i = 0, j =0, ran = 0;
  srand(time(NULL));
  fp = fopen("text.txt", "r");

  //get size of the file
  for(; fgets(words , sizeof(words), fp); j++);

  ran = rand() % 10;
  rewind(fp);
  for( i = ran; i < j ; i++){
    fgets(words, sizeof(words), fp);
  }
  return words;
}

此函数的目标是从文本文件返回单词列表,之后,我在文件中写入。 我的指针错误到底在哪里?

0 个答案:

没有答案