I keep getting an error when trying to assign my pointer to the arrays I have declared. The error is 'char *' differs in levels of indirection from 'char (*)[100]'. I am following the syntax in the book.
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define str_length 100
int main()
{
char str1[100]; /* array for first string */
char str2[100]; /* array for second string */
char *pstr1 = NULL; /* pointer to str1 */
char *pstr2 = NULL; /* pointer to str2 */
int count1; /* length of str1 */
int count2; /* length of str2 */
char more ; /* variable to continue with the loop y||Y */
int i = 0; /*loop counter */
do
{
pstr1 = &str1; /* get the address of str1 */
pstr2 = &str2; /* get the address of str2 */
printf("Please enter the first word\n"); /* ask for user input */
scanf("%s", pstr1); /* take the input into the buffer */
count1 = strlen(pstr1); /* get the length of the string */
printf("Please enter the second word\n"); /* ask for user input */
scanf("%s", pstr2); /* take the input into the buffer */
count2 = strlen(pstr2); /* get the length of the string */
/* concatenate str2 to end of str1 */
if(count1 == count2 ||count1 < count2 )
{
for(i = 0; i < count1; i++)
printf(" you entered %c\n", *(*pstr1 + i));
/*printf(" %s %s and \n", pstr1,pstr2);
printf(" %s %s\n",strrev(pstr1), pstr2);*/
}
else
/* concatenate str1 to end of str2 */
{
printf(" %s %s and \n", pstr2,pstr1);
printf(" %s %s \n",strrev(pstr2),pstr1);
}
printf(" Would you like to continue? y or n:\n"); /* ask user if they want to enter more data */
scanf("%c", &more); /* read the input */
while(getchar() != '\n') ; /* flush input buffer it appears that the scanf leaves a \n inthe buffer */
}while(more == 'y' || more == 'Y'); /*Test to continue or not*/
return 0;
}