meileur
This commit is contained in:
24
getfuncs.c
24
getfuncs.c
@@ -8,9 +8,9 @@
|
||||
int getFileLength(){
|
||||
/*variables*/
|
||||
FILE* stream;
|
||||
int length = 0;
|
||||
int file_length = 0;
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
size_t length = 0;
|
||||
ssize_t read;
|
||||
|
||||
/*prog*/
|
||||
@@ -19,12 +19,12 @@ int getFileLength(){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while((read = getline(&line, &len, stream)) != -1){
|
||||
length++;
|
||||
while((read = getline(&line, &length, stream)) != -1){
|
||||
file_length++;
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
return length-1;
|
||||
return file_length-1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -37,7 +37,7 @@ int fetchWord(char* fullword, int file_length){
|
||||
char read[8];
|
||||
unsigned int counter = 0;
|
||||
int char_size = (int) sizeof(char);
|
||||
int lign=0;
|
||||
int line=0;
|
||||
int offset=0;
|
||||
|
||||
/*prog*/
|
||||
@@ -47,14 +47,15 @@ int fetchWord(char* fullword, int file_length){
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(lign=0; lign<random; lign++){
|
||||
while(*read!='\n'){
|
||||
while((!feof(stream))&&(offset!=random)){
|
||||
fread(read, sizeof(char), 1, stream);
|
||||
if(*read=='\n'){
|
||||
offset++;
|
||||
}
|
||||
*read=' ';
|
||||
}
|
||||
|
||||
*read=' ';
|
||||
|
||||
while(*read!='\n'){
|
||||
fread(read, sizeof(char), 1, stream);
|
||||
fullword[counter] = *read;
|
||||
@@ -65,16 +66,15 @@ int fetchWord(char* fullword, int file_length){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
int main(void){
|
||||
/*variables*/
|
||||
int flength;
|
||||
char fullword[128];
|
||||
|
||||
/*prog*/
|
||||
flength = getFileLength();
|
||||
if(fetchWord(fullword, flength)!=-1){
|
||||
printf("%s", fullword);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}*/
|
||||
Reference in New Issue
Block a user