我有一个小问题。我想采用函数中使用的变量“posLigne”。这里是
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TAILLE_VIDE 30
#define TAILLE_MAX 1000
#include <ctype.h>
int ar(char mot);
static int compare (void const *a, void const *b);
void indexation(FILE *f,char tChar[][100],char filename[],int *posLigne);
int motVide(char *mot);
int main()
{
FILE *f=NULL;
int posLigne=1;
f=fopen("test.txt","r+");
int i;
char tChar[100][100];
char X[100][100];
int maju[100];
indexation(f,tChar,"test.txt",&posLigne);
charaff(tChar,7);
printf("%d",pos(tChar[1]));
return 0;
}
void indexation(FILE *f,char tChar[][100],char filename[],int *posLigne)
{
char nbr[100]="";
int i=0,j=0,l=1,k=0;
char ligne[TAILLE_MAX]="";
char mot[100]="";
while (fgets(ligne,TAILLE_MAX,f))
{
i=0;
while (ligne[i]!='\0')
{
memset (mot, 0, sizeof (mot));
while (!(ar(ligne[i])))
{
mot[k]=ligne[i];
k++;i++;
}
k=0;
// if (!(motVide((mot))))
if(!motVide(mot))
{
strcat(tChar[j],mot);
strcat(tChar[j]," ");
strcat(tChar[j],filename);
strcat(tChar[j]," ");
sprintf(nbr,"%d",l);
strcat(tChar[j],nbr);
strcat(tChar[j]," ");
sprintf(nbr,"%d",*posLigne);
strcat(tChar[j],nbr);
*posLigne++;
j++;
}
i++;
}
l++;
}
}
只关注变量“posLigne”,当我想将它用作局部变量时,它工作得很好。但是当我想使用指针通过引用传递时,它会显示大数字。
谢谢你,有一个美好的一天