userpl 0 Newbie Poster

Hello

This program read file and then it uses strcspn() to split strings. It displays words. I'd like to modify program now to check if variable "moja" equals some of words in "pairs.txt". If that's true, user should can write into "moja" every word from "pairs.txt" except words being in line where is actual word in "moja".
Now "moja" = "baza2" so user should can write into "moja" only words from second line of "pairs.txt". Could you give me any tips?
PS. sorry for my english.

pairs.txt

baza1;baza2;baza3
zamek1;zamek2;zamek3

file.cpp

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std; 
int pairs()
{
   
static const char filename[] = "pairs.txt"; 
FILE *file = fopen(filename, "r");
if ( file )
{
char line[BUFSIZ]; 
int k = 0;
while ( fgets(line, sizeof line, file) ) 
{
int i;
char *token = line;
printf("linia %d:\n", ++k);
for ( i = 0; *token; ++i ) 
{

size_t len = strcspn(token, ";\n");

printf("lancuch[%2d] = \"%*.*s\"\n", i, (int)len, (int)len, token);

token += len + 1;
}
const char* moja = "baza2"; 
}
fclose(file);
}    
}

int main(void)
{
    pairs();
    system("PAUSE");
    return EXIT_SUCCESS;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.