I want to extract all the words from this file (each word on 1 line)
mytab24112.txt
Code:
apple:$1$$Tnq7a6/C1wwyKyt0V/.BP/
orange:$6$$/xMg2/4CZwMUbah4IhNwCjqzZf0/OByfs6UHmq32jFbsdpbDw9bhLttC7n/bAVlM2NwJ7hBQ3d0H47leLXE6g1
banana:$1$$zZQKNjRd94GHyYOwXuStf0
a:$1$$Ij31LCAysPM23KuPlm1wA/
a:$6$$ek/ucQg0IM8SQLyD2D66mpoW0vAF26eA0/pqoN95V.F0nZh1IFuENNo0OikacRkDBk5frNqziMYMdVVrQ0o.51
aah:$1$$bh5o1cAKfH43fc/B1.AjF0
aah:$6$$jdxDww2LkNSlQPmWe5iDRAoBBT5IXa9241nN2bcm2Aukdrr4iH27Y6dj801MjLFaDQxbDBNxY4jvlXdIemiCY/
aahed:$1$$zA2Ef92JR9W7kqAf8Km5B0
aahed:$6$$mYQU7f3NL9Dysccvwv2BAyiCb/gxh9lN1gGnC9sa2uwHGX9VVb7jp3b7u/EZbdObqWrRFgiOLcRn7PEW1cOcz.
but with this code
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
int main(void){
char buf[1024];
char **arr1 = NULL;
char **arr2 = NULL;
int size1 = 0;
int size2 = 0;
FILE * f1, *f2;
f1 = fopen("mytab24112word.txt", "w+");
f2 = fopen("mytab24112.txt", "r");
while(fgets(buf, 1024, f1))
{
size1++;
arr1 = realloc(arr1, sizeof(char*) * size1);
arr1[size1 - 1] = strdup(buf);
}
while(fgets(buf, 1024, f2))
{
size2++;
arr2 = realloc(arr2, sizeof(char*) * size2);
arr2[size2 - 1] = strdup(buf);
}
char line[1000];
char * hash2;
char * del2;
char word[sizeof(line)];
// Read mytab24112.txt line by line
for(int j = 0; j < size2; j++){
strcpy(line, arr2[j]);
// Returns the password text using delimiter ':'
strcpy(word, line);
del2 = strchr(word, ':');
if (del2 != 0)
*del2 = '\0';
//Puts all iterations of word into f1, which is mytab24112word.txt
fputs(word,f1);
}// End of "for(int j = 0; j < size2; j++)" loop
}//End of main
but I end up with this.
mytab24112word.txt
Code:
appleorangebananaaaaahaahaahedaahed
How do I go about achieving this result?
Desired output for mytab24112word.txt
Code:
apple
orange
banana
a
a
aah
aah
aahed
aahed