Problems with string arrays, strcpy and strings - c

I'm having real trouble working with strings and string arrays, and using strcpy correctly. I'm using a dictionary of words scanned in a 2D array dictionary. Then I take a start word, alter every letter of it to create many different variants, i.e cat -> cbt, cct, cdt, etc. From there I copy each generated word into a 2D array and to compare these generated words to the dictionary to see if they are real words. I then want to print these real words, i.e cat as a start word will generate bat if its in the dictionary, but zat won't be. When I run the code it prints all the generated words but when It gets to check_dictionary function it prints no words.
The text file it reads from is like:
mat
yes
cat
hat
The code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_WORDS 20000
#define MAX_WORD_LENGTH 30
#define ARGS_REQUIRED 2
typedef struct scanned_words
{
char startword[MAX_WORD_LENGTH];
char endword[MAX_WORD_LENGTH];
} Scanned_words;
Scanned_words scan_two_words(Scanned_words words);
void get_next_word(Scanned_words words,
char parentwords[MAX_WORDS][MAX_WORD_LENGTH]);
void read_file(char * argv[], char dictionary[MAX_WORDS][MAX_WORD_LENGTH]);
void check_dictionary(char dictionary[MAX_WORDS][MAX_WORD_LENGTH],
char parentwords[MAX_WORDS][MAX_WORD_LENGTH]);
void usage(char * argv[]);
int main(int argc, char * argv[])
{
char dictionary[MAX_WORDS][MAX_WORD_LENGTH];
char nextword[MAX_WORDS][MAX_WORD_LENGTH];
char parentwords[MAX_WORDS][MAX_WORD_LENGTH];
Scanned_words words;
if (argc == ARGS_REQUIRED)
{
system("clear");
read_file(&argv[1], dictionary);
words = scan_two_words(words);
get_next_word(words, parentwords);
check_dictionary(dictionary, parentwords);
}
else
{
usage(&argv[0]);
}
return 0;
}
void read_file(char * argv[], char dictionary[MAX_WORDS][MAX_WORD_LENGTH])
//reads the text file and stores the dictonary as a 2D array
{
FILE * file_name;
int word_count = 0, i;
if ((file_name = fopen(argv[0], "r")) == NULL )
{
printf("Cannot open file ... \n");
}
while (fscanf(file_name, "%s", dictionary[i++]) == 1)
{
printf("%s ", dictionary[word_count]);
word_count++;
}
printf("\n");
printf("\n%d words scanned in from: %s\n\n", word_count, argv[0]);
}
Scanned_words scan_two_words(Scanned_words words)
//takes an empty structure, scans both words in and returns them in the same structure
{
printf("Enter the start word: \n");
scanf("%s", words.startword);
printf("\nEnter the end word: \n");
scanf("%s", words.endword);
printf("\n");
return words;
}
void get_next_word(Scanned_words words,
char parentwords[MAX_WORDS][MAX_WORD_LENGTH])
//get all eligible second words from original start word
{
char character;
char currentword[MAX_WORD_LENGTH];
int i;
strcpy(currentword, words.startword);
for (i = 0; currentword[i] != '\0'; i++)
{
strcpy(currentword, words.startword);
for (character = 'a'; character <= 'z'; character++)
{
currentword[i] = character;
strcpy(parentwords[i], currentword);
printf("%s ", parentwords[i]);
}
}
parentwords[i][0] = '\0';
printf("\n\n");
}
void check_dictionary(char dictionary[MAX_WORDS][MAX_WORD_LENGTH],
char parentwords[MAX_WORD_LENGTH][MAX_WORD_LENGTH])
//checks a generated word for eligibility against the dictionary, prints next generation words
{
int i, j;
printf("\nSecond words: \n\n");
for (j = 0; parentwords[j][0] != '\0'; j++)
;
{
for (i = 0; dictionary[i][0] != '\0'; i++)
{
if ((strcmp(dictionary[i], parentwords[j])) == 0)
{
printf("%s \n", parentwords[j]);
}
}
}
}
void usage(char * argv[])
//prints error message
{
printf("Incorrect usage, try: ./program_name %s\n", argv[1]);
}

The formatting revealed this:
for (j = 0; parentwords[j][0] != '\0'; j++)
;
which most probably was meant to be:
for (j = 0; parentwords[j][0] != '\0'; j++)
Here
while (fscanf(file_name, "%s", dictionary[i++]) == 1)
the i is used uninitialised
So change it definition to include an initialisation:
int word_count = 0, i = 0;

Related

C, custom reading from file into struct

Can you guys please check this and tell me what am I doing wrong?
I am trying to read from a txt into a struct
The file looks like this: (name on a line, followed by 4 attributes on the next line)
NAME SURNAME OTHER
a1 a2 a4 a3
OTHER ANOTHER
s2 s3 s4 s5
I have to read the file into a struct, then search for a name and print the number of comparisons it took till you found it (the names in the file are alphabetically sorted - I guess binary search is optimal).
Here is what I wrote for now:
*note: I know for certain that the file will have 10000 lines and the full name has at most 40 chars
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct student
{
char name[40];
char arg1[10];
char arg2[10];
char arg3[10];
char arg4[10];
}STUD;
STUD studies[5000];
STUD *ptr = studies;
void readlines(FILE *f)
{
char line[40];
char secondline[40];
int i=0;
while(fgets(line, 40, f) != NULL) //read first line -> here has to be student's name
{
sscanf(line, "%[^\n]%*c\n", studies[i].name); //store first line ->student's name
fgets(secondline, 40, f); //read second line -> here has to be additional information
sscanf(secondline, "%s %s %s %s", studies[i].arg1, studies[i].arg2, studies[i].arg3, studies[i].arg4);
i++;
}
}
void binary_search_string(STUD *arr, char x[])
{
//printf("sizeof: %ld\n", sizeof(arr));
int l=0;
int r = 4999;
int mid;
int compare=0;
while(l <= r)
{
mid = (l + r)/2;
printf("%s\n", studies[mid].name);
if(strcmp(studies[mid].name, x) == 0)
{
compare++;
printf("%d comparisons to find %s\n", compare, x);
break;
}
else
{
if(strcmp(studies[mid].name, x) < 0)
{
compare++;
l = mid + 1;
}
else
{
compare++;
r = mid - 1;
}
}
//printf("compare: %d\n", compare);
}
}
void print(STUD *array)
{
for(int i=0; i<sizeof(array); i++)
{
printf("%s %s %s %s %s\n", studies[i].name, studies[i].arg1, studies[i].arg2, studies[i].arg3, studies[i].arg4);
}
}
int main(int argc, char **argv)
{
if(argc < 2)
{
printf("usage: ./exe file_to_open\n");
exit(-1);
}
FILE *fp = fopen(argv[1], "r");
if(fp == NULL)
{
return 1;
}
char x[]="SURNAME NAME";
readlines(fp);
print(studies);
binary_search_string(studies, x);
fclose(fp);
return 0;
}
Another thing I am not sure about is how would the function "readlines" look like when using the pointer to the array of struct (ptr). (Can you guys give me an example here?)
I am sorry in advance if this is a stupid question.
Thank you!

Find number of occurrences for the substring in a string using C programming

I am trying a program in c to read a text file that contains array of characters or a string and find the number of occurrences of the substring called "GLROX" and say sequence found when it is found. And the "inputGLORX.txt" contains following string inside it.
GLAAAROBBBBBBXGLROXGLROXGLROXGLROXGLCCCCCCCCCCCCCCROXGGLROXGLROXGLROXGLROXGLROXGLROXGLROXGLROXGLROXGLROXGLROX
But i am getting wierd results. It would be great if some expert in C-programming helps me to solve this and thanks in advance.
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define NUMBER_OF_STRINGS 40
#define MAX_STRING_SIZE 7
void seqFound()
{
printf("Sequence Found\n");
}
int main()
{
FILE *fp;
char buff[1000];
char strptrArr[NUMBER_OF_STRINGS] [MAX_STRING_SIZE];
const char *search = "GLROX";
fp = fopen("D:/CandC++/inputGLORX.txt", "r");
if(fp==NULL)
printf("It is a null pointer");
while(!feof(fp))
{
//fscanf(fp, "%s", buff);
fgets(buff, 1000,fp);
}
int len = strlen(buff);
printf("length is %d\n",len);
int count = 0;
char *store;
while(store = strstr(buff, search))
{
printf("substring is %s \n",store);
count++;
search++;
}
printf("count is %d\n",count);
while (count!=0) {
seqFound();
count--;
}
return 0;
}
As said in the comment, their are at least 2 problems in the code: your fgets will only fetch the last line (if it fetch one at all ? In any case, this is not what you want), and you are incrementing the search string instead of the buff string.
Something like this should fix most of your problems, as long as no lines in your file are longer than 999 characters. This will not work properly if you use the \n or NULL characters in your search string.
int count = 0;
while (fgets(buff, 1000, fp) != NULL)
{
char *temp = buff;
while ((temp = strstr(temp, search)))
{
printf("%d. %s\n", count + 1, temp);
count++;
temp++;
}
}
Here is a main for testing. I used argv to provide the input.txt and the search string.
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
FILE *fp;
char buff[1000];
char *search;
if (argc < 3)
return (-1);
search = argv[2];
if (search[0] == '\0')
return (-1);
if ((fp = fopen(argv[1], "r")) == NULL)
return (-1);
int count = 0;
while (fgets(buff, 1000, fp) != NULL)
{
char *temp = buff;
while ((temp = strstr(temp, search)))
{
printf("%d. %s\n", count + 1, temp);
count++;
temp++;
}
}
printf("Match found: %d\n", count);
return 0;
}
The way you search in buff is wrong, i.e. this code:
while(store = strstr(buff, search))
{
printf("substring is %s \n",store);
count++;
search++; // <------- ups
}
When you have a hit, you change search, i.e. the string you are looking for. That's not what you want. The search string (aka the needle) shall be the same all the time. Instead you want to move forward in the buffer buff so that you can search in the remainder of the buffer.
That could be something like:
int main()
{
const char* buff = "GLAAAROBBBBBBXGLROXGLROXGLROXGLROXGLCCCCCCCCCCCCCCROXGGLROXGLROXGLROXGLROXGLROXGLROXGLROXGLROXGLROXGLROXGLROX";
const char* search = "GLROX";
const char* remBuff = buff; // Pointer to the remainder of buff
// Initialized to be the whole buffer
const char* hit;
int cnt = 0;
while((hit = strstr(remBuff, search))) // Search in the remainder of buff
{
++cnt;
remBuff = hit + 1; // Update the remainder pointer so it points just 1 char
// after the current hit
}
printf("Found substring %d times\n", cnt);
return 0;
}
Output:
Found substring 15 times

Load content of a file line by line into an array in C

I am coding a song database. For now, the data of 2 songs are stored in a text file, one struct field per line. I would like to copy the content of the file line by line into an array, and I do not get why the program crashes after calling load(). Is it a problem related to fgets()? Or when I replace '\n' by '\0'?
Here are the interesting parts of the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "functions.h"
int main()
{
int menu;
bool exit = false;
/*char title[256];
char artist[256];
char album[256];*/
int year;
Song **songs = NULL; // base pointer to the array (of pointers to struct)
FILE *f; // pointer to a file structure
int n = 0; // height of array at the beginning (= number of pointers to struct)
int i;
f = fopen("database.txt", "r+");
if(f == NULL)
return 0;
count_songs_db(f, &n); // will modify n (height of array) according to the number of existing songs
printf("n = %d\n", n);
songs = (Song**)malloc(n*sizeof(Song));
load(f, songs, n);
// MENU
for(i = 0 ; i < n ; ++i)
free(songs[i]);
free(songs);
fclose(f);
return 0;
}
functions:
void count_songs_db(FILE *f, int *n) // calculate how many songs there are already in the database.
{
int c, n_lines = 0;
while ((c = getc(f)) != EOF)
if (c == '\n')
++n_lines; // count number of lines
*n = n_lines/6; // 1 song = 6 lines. Changes the height of array accordingly.
rewind(f); // go back to beginning of file, to be able to load the db
}
void load(FILE *f, Song **songs, int n) // load existing songs (in the file) into the array
{
int i;
for(i = 0 ; i < n ; ++i)
{
fgets(songs[i]->title, 256, f); // reads a line of text
songs[i]->title[strlen(songs[i]->title)-1] = '\0'; // to replace \n by \0 at the end // not working?
fgets(songs[i]->artist, 256, f);
songs[i]->title[strlen(songs[i]->artist)-1] = '\0';
fgets(songs[i]->album, 256, f);
songs[i]->title[strlen(songs[i]->album)-1] = '\0';
fscanf(f, "%d\n", &(songs[i]->year)); // use it like scanf
fgets(songs[i]->genre, 256, f);
songs[i]->title[strlen(songs[i]->genre)-1] = '\0';
fscanf(f, "%d:%d\n", &(songs[i]->length.m), &(songs[i]->length.s));
}
for(i = 0 ; i < n ; ++i)
{
printf("Title: %s\n", songs[i]->title);
printf("Artist: %s\n", songs[i]->artist);
printf("Album: %s\n", songs[i]->album);
printf("Year of release: %d\n", songs[i]->year);
printf("Genre: %s\n", songs[i]->genre);
printf("Length: %d:%d\n", songs[i]->length.m, songs[i]->length.s);
}
}
struct:
typedef struct Length {
int m, s;
} Length;
typedef struct Song {
char title[256];
char artist[256];
char album[256];
int year;
char genre[256];
Length length;
} Song;
Thanks for your help.
Edit: I modified the code to use a simple array of struct. Here is the add_song() function and save() function:
void add_song(Song *songs, int *n)
{
printf("Title: ");
read(songs[*n].title, MAX_SIZE); // another function is used instead of scanf(), so the user can enter string with spaces. Also more secure.
printf("Artist: ");
read(songs[*n].artist, MAX_SIZE);
printf("Album: ");
read(songs[*n].album, MAX_SIZE);
printf("Year of release: ");
songs[*n].year = read_long(); // still have to check the user inputs (ie. year has to be between 1900 and 2017)
printf("Genre: ");
read(songs[*n].genre, MAX_SIZE);
printf("Length: \nmin: ");
songs[*n].length.m = read_long();
printf("sec: ");
songs[*n].length.s = read_long();
++(*n);
}
void save(FILE *f, Song *songs, int n) // save song in file
{
fprintf(f, "%s\n%s\n%s\n%d\n%s\n%d:%d\n", songs[n-1].title, songs[n-1].artist, songs[n-1].album, songs[n-1].year, songs[n-1].genre, songs[n-1].length.m, songs[n-1].length.s); // use it like printf. Prints the data in the file.
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
typedef struct Length {
int m, s;
} Length;
typedef struct Song {
char title[256];
char artist[256];
char album[256];
int year;
char genre[256];
Length length;
} Song;
void count_songs_db(FILE *f, int *n) // calculate how many songs there are already in the database.
{
int c, n_lines = 0;
while ((c = getc(f)) != EOF)
if (c == '\n')
++n_lines; // count number of lines
*n = n_lines / 6; // 1 song = 6 lines. Changes the height of array accordingly.
rewind(f); // go back to beginning of file, to be able to load the db
}
void load(FILE *f, Song *songs, int n) // load existing songs (in the file) into the array
{
int i;
for (i = 0; i < n; ++i)
{
fgets(songs[i].title, 256, f); // reads a line of text
songs[i].title[strlen(songs[i].title) - 1] = '\0'; // to replace \n by \0 at the end // not working?
fgets(songs[i].artist, 256, f);
songs[i].title[strlen(songs[i].artist) - 1] = '\0';
fgets(songs[i].album, 256, f);
songs[i].title[strlen(songs[i].album) - 1] = '\0';
fscanf(f, "%d\n", &(songs[i].year)); // use it like scanf
fgets(songs[i].genre, 256, f);
songs[i].title[strlen(songs[i].genre) - 1] = '\0';
fscanf(f, "%d:%d\n", &(songs[i].length.m), &(songs[i].length.s));
}
for (i = 0; i < n; ++i)
{
printf("Title: %s\n", songs[i].title);
printf("Artist: %s\n", songs[i].artist);
printf("Album: %s\n", songs[i].album);
printf("Year of release: %d\n", songs[i].year);
printf("Genre: %s\n", songs[i].genre);
printf("Length: %d:%d\n", songs[i].length.m, songs[i].length.s);
}
}
int main()
{
int menu;
bool exit = false;
/*char title[256];
char artist[256];
char album[256];*/
int year;
Song *songs = NULL; // base pointer to the array (of pointers to struct)
FILE *f; // pointer to a file structure
int n = 0; // height of array at the beginning (= number of pointers to struct)
int i;
f = fopen("database.txt", "r+");
if (f == NULL)
return 0;
count_songs_db(f, &n); // will modify n (height of array) according to the number of existing songs
printf("n = %d\n", n);
songs = (Song*)malloc(n * sizeof(Song));
load(f, songs, n);
// MENU
free(songs);
fclose(f);
return 0;
}

Read from a text file and use each line to compare if they are anagrams

I must modify my program to accept input from
a file called anagrams.txt.This file should have two strings per line, separated by the # character. My program should read
each pair of strings and report back if each pair of strings is an anagram. For example consider the following content of anagrams.txt:
hello#elloh
man#nam
Astro#Oastrrasd
Your program should print out the following:
hello#elloh - Anagrams!
man#nam - Anagrams!
Astro#Oastrrasd- Not anagrams!
I should compile in g++
Here is the code to read from text:
int main()
{
char input[30];
if(access( "anagrams.txt", F_OK ) != -1) {
FILE *ptr_file;
char buf[1000];
ptr_file =fopen("anagrams.txt","r"); if (!ptr_file)
return 1;
while (fgets(buf,1000, ptr_file)!=NULL)
printf("%s",buf);
fclose(ptr_file);
printf("\n");
}
else{ //if file does not exist
printf("\nFile not found!\n");
}
return 0;
}
Code to find if the text are anagrams:
#include <stdio.h>
int find_anagram(char [], char []);
int main()
{
char array1[100], array2[100];
int flag;
printf("Enter the string\n");
gets(array1);
printf("Enter another string\n");
gets(array2);
flag = find_anagram(array1, array2);
if (flag == 1)
printf(" %s and %s are anagrams.\n", array1, array2);
else
printf("%s and %s are not anagrams.\n", array1, array2);
return 0;
}
int find_anagram(char array1[], char array2[])
{
int num1[26] = {0}, num2[26] = {0}, i = 0;
while (array1[i] != '\0')
{
num1[array1[i] - 'a']++;
i++;
}
i = 0;
while (array2[i] != '\0')
{
num2[array2[i] -'a']++;
i++;
}
for (i = 0; i < 26; i++)
{
if (num1[i] != num2[i])
return 0;
}
return 1;
}
You can try something like this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXLINE 1000
#define MAXLETTER 256
int is_anagram(char *word1, char *word2);
void check_lines(FILE *filename);
int cmpfunc(const void *a, const void *b);
void convert_to_lowercase(char *word);
int
main(int argc, char const *argv[]) {
FILE *filename;
if ((filename = fopen("anagram.txt", "r")) == NULL) {
fprintf(stderr, "Error opening file\n");
exit(EXIT_FAILURE);
}
check_lines(filename);
fclose(filename);
return 0;
}
void
check_lines(FILE *filename) {
char line[MAXLINE];
char *word1, *word2, *copy1, *copy2;
while (fgets(line, MAXLINE, filename) != NULL) {
word1 = strtok(line, "#");
word2 = strtok(NULL, "\n");
copy1 = strdup(word1);
copy2 = strdup(word2);
convert_to_lowercase(copy1);
convert_to_lowercase(copy2);
if (is_anagram(copy1, copy2)) {
printf("%s#%s - Anagrams!\n", word1, word2);
} else {
printf("%s#%s - Not Anagrams!\n", word1, word2);
}
}
}
void
convert_to_lowercase(char *word) {
int i;
for (i = 0; word[i] != '\0'; i++) {
word[i] = tolower(word[i]);
}
}
int
is_anagram(char *word1, char *word2) {
qsort(word1, strlen(word1), sizeof(*word1), cmpfunc);
qsort(word2, strlen(word2), sizeof(*word2), cmpfunc);
if (strcmp(word1, word2) == 0) {
return 1;
}
return 0;
}
int
cmpfunc(const void *a, const void *b) {
if ((*(char*)a) < (*(char*)b)) {
return -1;
}
if ((*(char*)a) > (*(char*)b)) {
return +1;
}
return 0;
}
Since this looks like a University question, I won't provide a full solution, only a hint.
All you have to do is replace the stdin input part of the anagram-finding file with the code you wrote to read from a file: it's as simple as changing
printf("Enter the string\n");
gets(array1);
printf("Enter another string\n");
gets(array2);
to
// before program:
#define SIZE 1000
// inside main
if (access("anagrams.txt", F_OK) == -1){
printf("\nFile not found!\n");
return 1; // Abort the program early if we can't find the file
}
FILE *ptr_file;
char buf[1000];
ptr_file = fopen("anagrams.txt","r");
if (!ptr_file)
return 1;
char array1[SIZE], array2[SIZE];
while (fgets(buf, 1000, ptr_file)!=NULL){
// do all your anagram stuff here!
// there is currently one line of the input file stored in buf
// Hint: You need to split buf into array_1 and array_2 using '#' to separate it.
}
fclose(ptr_file);
printf("\n");
Additional comments:
Don't ever ever ever use gets. gets doesn't check that the string it writes to can hold the data, which will cause your program to crash if it gets input bigger than the array size. Use fgets(buf, BUF_SIZE, stdin) instead.
Beautiful code is good code. People are more likely to help if they can read your code easily. (fix your brackets)
Just for interest, a more efficient algorithm for checking anagrams is to use qsort to sort both arrays, then a simple string matcher to compare them. This will have cost O(mnlog(m+n)), as opposed to O(m^2 n^2), awith the current algorithm
You need to split every line you read by fgets (as you did) in to two strings, and pass them to your find_anagram function. You can do that using strtok:
int main()
{
int flag;
char buf[1000];
FILE *ptr_file;
//Check file existence
//Open the file for reading
while (fgets (buf, 1000, ptr_file) != NULL)
{
char *array1 = strtok(buf, "#");
char *array2 = strtok(NULL, "\n");
flag = find_anagram (array1, array2);
//Check flag value to print your message
}
return 0;
}
//put your find_anagram function
Don't forget to #include <string.h> to use strtok().

Reading a file of strings to a string array

I'm trying to read a file (full of a word followed by a newline), to an array full of pointers to each string. Then print each word in the array, and count the number of words read. However it just prints no words and says 0 words imported.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ARGS_REQUIRED 2
#define MAX_WORDS 50
#define MAX_WORD_LENGTH 1024
void read_file (char * argv[], char word_storage[]);
void usage (char * argv[]);
int main (int argc, char* argv[])
{
char word_storage[MAX_WORDS];
if (argc == ARGS_REQUIRED)
{
system("clear");
read_file(&argv[1], word_storage);
}
else
{
usage(&argv[0]);
}
return 0;
}
void usage (char * argv[])
{
printf("Incorrect usage, try: ./program_name %s\n", argv[1]);
}
void read_file (char * argv[], char word_storage[])
{
FILE * file_name;
char *word[MAX_WORDS][MAX_WORD_LENGTH];
int word_count = 0, i = 0, j;
if ((file_name = fopen(argv[0], "r")) == NULL)
{
printf("Cannot open file ... \n");
}
while (fscanf(file_name, "%s", *word[MAX_WORDS]) == 1)
{
for (j = 0; j < MAX_WORDS; j++)
{
if (printf("%s\n", *word[j]) == 1)
{
word_count++;
}
}
}
fclose(file_name);
printf("Imported words: %d\n", word_count);
}
You can modify your program as below. It worked for me. Please add error check for printf() function.
void read_file (char * argv[], char word_storage[])
{
FILE * file_name;
char word[MAX_WORDS][MAX_WORD_LENGTH];
int word_count = 0, i = 0, j;
if ((file_name = fopen(argv[0], "r")) == NULL)
{
printf("Cannot open file ... \n");
}
while (fscanf(file_name, "%s", word) == 1)
{
printf("%s\n",word);
word_count++;
/*
for (j = 0; j < MAX_WORDS; j++)
{
if (printf("%s\n", word[j]) == 1)
{
word_count++;
}
}
*/
}
fclose(file_name);
printf("Imported words: %d\n", word_count);
}

Resources