Witam
Oto kod:
[code]
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(void)
{
string moja = "bank1";
static const char filename[] = "pairs.txt"; /* the name of a file to open */
FILE file = fopen(filename, "r"); / try to open the file /
if ( file )
{
char line[BUFSIZ]; / space to read a line into /
int k = 0;
while ( fgets(line, sizeof line, file) ) / read each line */
{
int i;
char token = line; / point to the beginning of the line */
printf("line %d:\n", ++k);
for ( i = 0; token; ++i ) / loop through each character on the line /
{
/ search for delimiters /
size_t len = strcspn(token, ";\n");
/ print the found text: use . in format to specify a maximum print size /
printf("token[%2d] = "%.s"\n", i, (int)len, (int)len, token);
/ advance pointer by one more than the length of the found text */
token += len + 1;
}
}
fclose(file);
}
return 0;
return EXIT_SUCCESS;
}
[/code]
Plik pairs.txt
[code]
bank1;bank2;bank3;bank4
urzad1;urzad2;urzad3;urzad4
[/code]
Chcialbym, aby program sprawdzal czy zawartosc zmiennej "moja" znajduje sie w pliku "pairs.txt". Jesli tak to powinien pozwolic uzytkownikowi na zmiane zmiennej "moja" na ktorys z lanucuchow znajdujacych sie w linii, w ktorej nie znajduje sie lanuch "bank1" (czyli 2 linia). Pomoze ktos?