Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello this C program is not complain with gcc -Wall .. can you help me fix it it shows this error [inessaid@scln2 ~]$ gcc

Hello this C program is not complain with gcc -Wall .. can you help me fix it it shows this error "

[inessaid@scln2 ~]$ gcc -Wall fileIO.c

fileIO.c: In function main:

fileIO.c:37: warning: missing braces around initializer

fileIO.c:37: warning: (near initialization for strArr[0])" the program is

#include

#include

#include

int are_anagram(char *word1, char* word2);

int read_line(char *str, int n);

int main(int argc , char ** argv)

{

if(argc < 2) // check file given in argument

{

printf("Usage : ./fileO.ang file_name ");

return 0;

}

if((strlen(argv[1]) > 100)) //check given file name should not more than 100 char

{

printf("Provide filename less then 100 characters ");

return 0;

}

char ofilename[100] = {0};

char strArr[1000][100] = {0};

int i =0 , j = 0 , k = 1;

int size = 0 ;

sprintf(ofilename,"%s.ang",argv[1]); // make output file name

FILE * fp = fopen(argv[1],"r"); // open read file

if(fp == NULL) // if not exist return

{

printf("Input file not exist ");

return 0;

}

while(fgets(strArr[i++],100,fp) != (char *)NULL) // get line by line

{

for(j=0;strArr[i-1][j];j++)

{

if(strArr[i-1][j] == ' ') // replace with null

{

strArr[i-1][j] = '\0';

break;

}

}

}

size = i-1;

fclose(fp); // close read file

fp = fopen(ofilename,"w+"); //open output file for write

if(fp == NULL) // check if is it open

{

printf("Output file can not open ");

return 0;

}

for( i =0 ;i < size ; i++) //check anagram

{

for(j=i+1 ; j

{

if(are_anagram(strArr[i], strArr[j]))

{

fprintf(fp,"%d %s %s ",k++,strArr[i],strArr[j]); // write in file if it is anagram

}

}

}

return 0;

}

int are_anagram(char *word1, char *word2)

{

int letter_counts[26]={0};

char *p; char *q;

int i, count =0;

char ch;

for(p = word1; *p!='\0'; p++)

if(isalpha(*p))

{

ch = tolower(*p);

letter_counts[ch - 'a']++;

}

for(q = word2; *q!='\0'; q++)

if(isalpha(*q))

{ ch = tolower(*q);

letter_counts[ch - 'a']--;

}

for(i =0;i<26;i++)

{

if(letter_counts[i]==0)

count++;

}

if(count == 26)

return 1;

else

return 0;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago