linux中No such file or directory 找不到文件的问题
#include<stdio.h>#include<stdlib.h>#include<string.h>#defineN20#defineMAXMOTS30voidli...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 20
#define MAXMOTS 30
void lireMots(char nomF[], int dim, char lm[][N+1], int *nbMots) {
FILE *fd;
char mot[N];
if ((fd=fopen(nomF,"r"))==NULL) {
perror(nomF);
exit(EXIT_FAILURE);
}
*nbMots = 0;
while (*nbMots<MAXMOTS && fscanf(fd, "%s", mot)>0) {
int lgDuMot = strlen(mot);
if (lgDuMot <= dim) {
strcpy(lm[(*nbMots)++],mot);
}
}
fclose(fd);
}
void printListe(char lm[][N+1], int nbMots) {
int i=0;
for ( ; i<nbMots; i++)
printf("%s\n", lm[i]);
}
int main(void) {
char laListeDesMots[MAXMOTS][N+1]; /* la liste des mots */
int nbMots;
lireMots("liste", N, laListeDesMots, &nbMots);
printListe(laListeDesMots, nbMots);
return EXIT_SUCCESS;
}
运行出来总是提示
No such file or directory
是什么原因啊??? 展开
#include <stdlib.h>
#include <string.h>
#define N 20
#define MAXMOTS 30
void lireMots(char nomF[], int dim, char lm[][N+1], int *nbMots) {
FILE *fd;
char mot[N];
if ((fd=fopen(nomF,"r"))==NULL) {
perror(nomF);
exit(EXIT_FAILURE);
}
*nbMots = 0;
while (*nbMots<MAXMOTS && fscanf(fd, "%s", mot)>0) {
int lgDuMot = strlen(mot);
if (lgDuMot <= dim) {
strcpy(lm[(*nbMots)++],mot);
}
}
fclose(fd);
}
void printListe(char lm[][N+1], int nbMots) {
int i=0;
for ( ; i<nbMots; i++)
printf("%s\n", lm[i]);
}
int main(void) {
char laListeDesMots[MAXMOTS][N+1]; /* la liste des mots */
int nbMots;
lireMots("liste", N, laListeDesMots, &nbMots);
printListe(laListeDesMots, nbMots);
return EXIT_SUCCESS;
}
运行出来总是提示
No such file or directory
是什么原因啊??? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |