Hi, im newbie in C, now I want to make a program which can search something in file (now it will be two letter word) I want to command it from cmd by test text.txt ab
i have a problem with argv filed, everytime when i run this script it fall.... :(
dvojice - two letters from cmd
soubor - file
if can anybody help me, i will be very happy :)
#include <stdio.h>
int main (int argc,char *argv[])
{
char dvojice[2],c;
FILE *soubor;
int i,counter,umisteni,vysledek[1000];
umisteni = 0;
dvojice[0] = argv[2][0];
dvojice[1] = argv[2][1];
if (argv[1]) {
soubor = fopen(argv[1],"r");
if (soubor != NULL) {
while((c=getc(soubor)) != EOF){
umisteni ++;
if (c == dvojice[0]){
c=getc(soubor);
umisteni ++;
if (c == dvojice[1]){
counter ++;
vysledek[counter]=umisteni;
printf("lokace: %d\n",umisteni - 1);
}
}
}
fclose(soubor);
printf("Provedeno OK\n");
} else {
printf("Nepodarilo se otevrit soubor: %s\n",argv[1]);
};
} else {
printf("Nebyl definovan nazev souboru!\n");
};
printf("Ukoncete stiskem klavesy Enter\n");
getchar();
return 0;
};