Jump to content

[fix]searching to compare word in word in file.txt

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
kiddies

kiddies

    Programmer

  • Members
  • PipPipPipPip
  • 130 posts
#include<stdio.h>

#include<string.h>

#include<stdlib.h>


void cari(void) {

	

	FILE *text;

	char *input;

	char namafile[25];

	

	printf("input your string :\n"); scanf("%s",input);

	printf("\n");

	printf("input your filename.txt :\n"); gets(text);

	

	if ((text = fopen(namafile, "r")) != NULL) {

		printf("[+]Searching\n");

		printf("[+]Found\n");

		printf("string : %s\n",&input);

		printf("[+]Match In filename\n");

		printf("%s",strcmp(input,&namafile);

	}else if ((text = fopen(namafile,"r")) != NULL) {

		printf("[+]Searching\n");

		printf("[+]Not Found\n");

		printf("string : %s\n",&input);

		printf("[+]Not Match In filename\n");

		printf("%s",strcmp(input,&namafile);

	} else {

		printf("kesalahan file bro");

		exit(EXIT_FAILURE);

	}

		fclose(text);

		return cari;

	}

	

int main(void) {

	cari();

	return 0;

}


help me to fix it dude

this my error dude..

seacrh.c: In function ‘cari’:

seacrh.c:13: warning: passing argument 1 of ‘fgets’ from incompatible pointer type

seacrh.c:13: error: too few arguments to function ‘fgets’

seacrh.c:18: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’

seacrh.c:20: warning: passing argument 2 of ‘strcmp’ from incompatible pointer type

seacrh.c:20: error: expected ‘)’ before ‘;’ token

seacrh.c:21: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’

seacrh.c:21: error: expected ‘;’ before ‘}’ token

seacrh.c:24: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’

seacrh.c:26: warning: passing argument 2 of ‘strcmp’ from incompatible pointer type

seacrh.c:26: error: expected ‘)’ before ‘;’ token

seacrh.c:27: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’

seacrh.c:27: error: expected ‘;’ before ‘}’ token

seacrh.c:32: warning: ‘return’ with a value, in function returning void

kiddies@ubuntu:~/c$ gcc -o seacrh seacrh.c

seacrh.c: In function ‘cari’:

seacrh.c:13: warning: passing argument 1 of ‘gets’ from incompatible pointer type

seacrh.c:18: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’

seacrh.c:20: warning: passing argument 2 of ‘strcmp’ from incompatible pointer type

seacrh.c:20: error: expected ‘)’ before ‘;’ token

seacrh.c:21: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’

seacrh.c:21: error: expected ‘;’ before ‘}’ token

seacrh.c:24: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’

seacrh.c:26: warning: passing argument 2 of ‘strcmp’ from incompatible pointer type

seacrh.c:26: error: expected ‘)’ before ‘;’ token

seacrh.c:27: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’

seacrh.c:27: error: expected ‘;’ before ‘}’ token

seacrh.c:32: warning: ‘return’ with a value, in function returning void


i hope enlightenment for this...

#2
speculatius

speculatius

    Newbie

  • Members
  • PipPip
  • 25 posts
Hello,

there are lot of mistakes.

1) line 13: gets(text)
You cant read input to variable of type FILE*. You should use scanf("%s", namafile)

2) line 20: printf("%s",strcmp(input,&namafile)
It will compare two strings - input and namafile. It is not very useful. You have to iterate over whole file and find for your input. I am not sure, but fscanf("%s", ...) should read file word by word (delimited by space or new line).

3) line 21: else if ((text = fopen(namafile,"r")) != NULL) {
Isnt it the same condition as on line 15??? What is it good for?

Try to fix it and if there were new errors, post it here.