Write a program that reads strings(words) from a text file and copy the inverted words to another file (use the command line arguments).
Form a new array of words b from original array a using the function
void formNewArray(char **a, char **b, int n, char (t)(char *));
where n is the number of words in array, and t is the pointer to function for inverting a string.
The following program gives SIGSEGV segmentation fault in function formNewArray():
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void form_temp_array(char **a,char **b,int n,char* (*t)(char *))
{
int i;
for(i=0 ;i<n; i++)
strcpy(b[i],(*t)(a[i]));
}
char* reverseWord(char *word)
{
char *new_word;
new_word=strrev(word);
return new_word;
}
void print(char **arr,int n)
{
int i;
for(i=0; i<n; i++)
printf("%s\n",arr[i]);
}
int main()
{
char* a[]={"PROGRAMMING","CODING"};
int n=sizeof(a)/sizeof(char**);
char* b[n];
printf("original words:\n");
print(a,n);
printf("reversed words:\n");
form_temp_array(a,b,n,&reverseWord);
print(b,n);
return 0;
}