Untitled

 avatar
unknown
c_cpp
2 years ago
778 B
3
Indexable
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int pos = 1;
    char string[50];
    char searched[50] = {0};

    FILE *f1 = fopen("J:\\Desktop\\BezpProg\\cw1\\test", "r");

    printf("please enter a word\n");
    scanf("%s", searched);
    while (fscanf(f1, "%s", string) == 1)
    {
        int length = 0;
        while(string[length]!='\0')
        {
            length++;
        }
        int counter = 0;
        for(int i = 0; i<length; i++){
            if(string[i] == searched[i]){
                counter++;
                if(counter == length){
                    printf("znaleziono slowo na pozycji - %d\n", pos);
                }
            }
        }
        pos++;
    }

    fclose(f1);
    return 0;
}
Editor is loading...