Question: I have two errors in my C program, how do i fix them? I've included the full program for more context for this segment of
I have two errors in my C program, how do i fix them? I've included the full program for more context
for this segment of code I am getting the error: invalid type argument of unary '*' (have 'int') on the line with the while statement
char removeSpaces( char ptr ){
while ( *ptr == ' ') ptr++; return ptr; }
this line of code I am getting the error: error: assignment makes pointer from integer without a cast [-Wint-conversion]|
ptr = removeSpaces( ptr );
full program:
#include
void removeNewLine( char *line){ line[ strlen(line) -1 ] = '\0'; }
char removeSpaces( char ptr ){
while ( *ptr == ' ') ptr++; return ptr; }
int main() {
while(1) {
// arrays to store cmd and arguments char line[80] = ""; int i = 0; int command = 1; int Redirection = 0;
// cleaning all the buffers fflush(0);
printf("myShell1$ "); fgets( line, 80, stdin);
char *ptr = line;
removeNewLine( line );
ptr = removeSpaces( ptr );
// Checking if there are arguments or just new line char if ( *ptr == ' ' ) continue;
if ( strcmp(ptr,"exit") == 0 ) return 0;
char *token; char sep[2] = " ";
token = strtok(line, sep);
while( token != NULL ) {
if ( command == 1 ){ printf("Command : %s ", token); command = 0; } else if ( *token == '-') { ++token;
while( *token != '\0'){ printf("Option : %c ", *token); ++token; } } else if ( strcmp(token,"<") == 0 ) { printf("File Redirection : %c ", *token); Redirection = 1; } else if ( strcmp(token,">") == 0 ) { printf("File Redirection : %c ", *token); Redirection = 1; } else if ( strcmp(token,"|") == 0 ) { printf("pipe "); command = 1; } else{
if ( Redirection == 1 ){ printf("File : %s ", token); Redirection = 0; } else printf("Argument : %s ", token); }
token = strtok(NULL,sep); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
