Hey, I have this simple lab that I'm working on, but I keep getting an error while compiling.
Here's the question:
**Write a program called lab09.c that
-prompts the user for a character and then a string.
-REMOVES all occurrences of that character from the string, and
-prints the changed string forwards and backwards.
The program must:
-use a macro (#define) to set MAX to 100 (maximum length of string is 99).
-define and use functions:
void squeeze( char c, char S[] ) ; /* removes all occurrences of c from S /
void printBackwards( char S[] ) ; / prints string in reverse */
-exit or return with code 0 (zero)
-behave exactly like given program lab09
The program may:
-use gets if you wish
You may Assume:
-user always gives correctly formatted input.
Note:
-when you pass an array/string to a function, any changes the function
makes to that array/string are permanent.
Examples of running given lab09:
./lab09
Enter a character:p
Enter a string max 99 characters:Peter Piper picked a peck of pickled peppers!
FWD:Peter Pier icked a eck of ickled eers!:
BWD:!sree delkci fo kce a dekci reiP reteP:**
And here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 100
char c;
char S[MAX];
void squeeze (char c, char S[]);
void printBackwards (char S[]);
int main (void)
{
printf("Enter a character: ");
scanf("%c", &c);
printf ("Enter a string max 99 characters: ");
scanf("%c", &S[MAX]);
printf("\n");
printf("FWD:");
squeeze (c, S[MAX]); //error here
printf("\n");
printf("BWD:");
printBackwards (S[MAX]); //error here
printf("\n");
return 0;
}
void squeeze (char c, char S[])
{
int i;
char fwd[MAX];
for ( i = 0; i < MAX; i++)
{
if ( S[i] == c )
{
S[i] = ''; //errorr here
}
fwd[MAX] += S[i];
}
printf ("%c", &S[i]);
}
void printBackwards (char S[])
{
int j;
char bckward[MAX];
for ( j = sizeof(S); j >= S[0]; j--)
{
bckward[MAX] += S[j];
}
printf("%c", &bckward[MAX]);
}
My errors:
lab09.c: In function 'main':
lab09.c:20: warning: passing argument 2 of 'squeeze' makes pointer from integer without a cast
lab09.c:23: warning: passing argument 1 of 'printBackwards' makes pointer from integer without a cast
lab09.c:36:11: error: empty character constant