I have an exercise that says:
Encode a program that reads through a keyboard a keyword of up to 15 characters and a text of up to n lines (n being a constant value). The program should eliminate from the text those lines that contain the keyword and print the "modified" text on the screen.
I have more or less an idea of how to save the keyword and the text by lines.
This is the code I have:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 4 //Este es el nº máximo de líneas
int main()
{
int i;
char clave[15];
char linea[20];
char *texto[MAX]; //array dinámico para el texto
printf("Introduce la palabra clave\n");
gets(clave);
for(i=0; i<MAX; i++)
texto[i]=NULL; //Inicializo a NULL
printf("Texto original\n=============\n");
for(i=0; i<MAX; i++)
{
printf("Introduce la %dº linea:\n",i);
gets(linea);//leo las lineas del texto
if(strstr(linea,clave)==NULL)
{
texto[i]=(char*) malloc(strlen(linea)+1);//guardo bloque
strcpy(texto[i],linea);//le adjudico las lineas al texto
}
}
From here I am stuck, How do I compare the keyword and identify it in the text lines to eliminate it, and print the modified text on the screen again?