Open karanmc opened 9 years ago
make sure there is none of those HEAD lines in code, <<<<<<< HEADm, ======= etc. Auto generated when merge for some reason.
ok, will check and compile again
like that d1a1cd10436e5c8215baad5f44c5edf1034907 random line
Yep, commented everything unnecessary out. A lot less error:
myshell.c: In function ‘main’: myshell.c:70:15: error: incompatible types when assigning to type ‘char[256]’ from type ‘char *’ command = "cd"; //switch to cd command ^ myshell.c:94:9: error: expected ‘;’ before ‘}’ token } ^
The error on line 94 is alright. The only thing is the command = "cd". not sure why that's an issue
I got rid of command = "cd" so idk why that would error, maybe update code to my commit?
also line 35 get rid of the r that i accidentally left in-front of the string "\myshell"
I can't find the 'r', but when I comment out the command="cd", the code compiles. I'll push the code to the repo
update your code to newest commit I changed the command = "cd" and other stuff in newest merge
ohh ok will do
myshell.c: In function ‘main’: myshell.c:35:18: error: ‘r’ undeclared (first use in this function) strcat(shell,r"\myshell");//store shells working directory ^ myshell.c:35:18: note: each undeclared identifier is reported only once for each function it appears in myshell.c:35:19: error: expected ‘)’ before string constant strcat(shell,r"\myshell");//store shells working directory ^ myshell.c:100:9: error: expected ‘;’ before ‘}’ token } ^ myshell.c:109:10: warning: implicit declaration of function ‘strcad’ [-Wimplicit-function-declaration] strcad(arg,"\n"); ^ myshell.c:114:10: warning: passing argument 1 of ‘fgets’ from incompatible pointer type [enabled by default] line = fgets(readme); ^ In file included from myshell.c:8:0: /usr/include/stdio.h:622:14: note: expected ‘char * restrict’ but argument is of type ‘struct FILE ’ extern char fgets (char restrict s, int __n, FILE restrict stream) ^ myshell.c:114:10: error: too few arguments to function ‘fgets’ line = fgets(readme); ^ In file included from myshell.c:8:0: /usr/include/stdio.h:622:14: note: declared here extern char fgets (char restrict s, int n, FILE *restrict stream) ^ myshell.c:115:22: warning: comparison between pointer and integer [enabled by default] while (line != EOF){ ^ myshell.c:117:14: warning: passing argument 1 of ‘fgets’ from incompatible pointer type [enabled by default] line = fgets(readme); ^ In file included from myshell.c:8:0: /usr/include/stdio.h:622:14: note: expected ‘char * restrict’ but argument is of type ‘struct FILE ’ extern char fgets (char *restrict s, int n, FILE restrict stream) ^ myshell.c:117:14: error: too few arguments to function ‘fgets’ line = fgets(readme); ^ In file included from myshell.c:8:0: /usr/include/stdio.h:622:14: note: declared here extern char fgets (char restrict s, int __n, FILE restrict stream) ^
my bad wasn't supposed to be bold lol
changed some stuff, add new commit and try again
ok
the files on github aren't updating. did you submit a merge request?
oh wait I got it
but it says "This branch has conflicts that must be resolved" and I can't merge it
it says all you need is write access
try some way of force merge
ok
here is code:
/*
*/
// Put macros or constants here using #define
// Put global environment variables here
// Define functions declared in myshell.h here
int main(int argc, char *argv[]) { // Input buffer and and commands char buffer[BUFFER_LEN] = { 0 }; char command[BUFFER_LEN] = { 0 }; char arg[BUFFER_LEN] = { 0 }; char cwd[BUFFER_LEN] = { 0 }; char line[BUFFER_LEN] = { 0 };
char shell[BUFFER_LEN] = { 0 };
getcwd(shell, sizeof(shell));
strcat(shell,"\\myshell");//store shells working directory
int paused = 0;
FILE *readme;
// Parse the commands provided using argc and argv
// Perform an infinite loop getting command input from users
while (fgets(buffer, BUFFER_LEN, stdin) != NULL)
{
// Perform string tokenization to get the command and argument
sscanf(buffer,"%s %s",command,arg); // Parse the commands provided using argc and argv
// Check the command and execute the operations for each command
//pause has priority, we want to check if paused or not before checking if its actually a command
if (strcmp(command,"pause")== 0 && paused != 0 && strcmp(arg, "") == 0){
paused = 1;
}
else if (paused == 0){
if (strcmp(buffer, "\n") == 0){
paused = 0;
}
}
// cd command -- change the current directory
else if (strcmp(command, "cd") == 0)
{
if (strcmp(arg,"")!= 0){
strcat(command," ");
strcat(command,arg);
system(command);
}
else{
system("pwd");
}
}
// directory listing
else if (strcmp(command, "dir") == 0 && strcmp(arg, "") == 0)
{
getcwd(cwd, sizeof(cwd)); //store cwd
strcpy(command,"cd"); //switch to cd command
strcat(command," ");
strcat(command,arg);
system(command);
system("ls"); // display all files (linux) within cwd
strcat(command," ");
strcat(command,cwd);
system(command);//cd back to stored cwd
}
//enviorment variables
else if (strcmp(command, "environ") == 0 && strcmp(arg, "") == 0)
{
system("printenv"); // again linux terminal usage
}
// clear command
else if (strcmp(command,"clr")== 0){
//system("cls"); // windows terminal usage
system("reset"); // linux terminal usage
}
// quit command -- exit the shell
else if (strcmp(command, "quit") == 0 && strcmp(arg, "") == 0)
{
return EXIT_SUCCESS;
}
// echo command -- repeat back argument then move to next line with \n
else if (strcmp(command, "echo") == 0 )
{
strcat(arg,"\n");
fputs(arg,stderr);
}
else if (strcmp(command, "help") == 0 && strcmp(arg, "") == 0){
readme = fopen("README.md", "rt");
fgets(line,BUFFER_LEN,readme);
while (line != EOF){
fputs(line,stderr);
line = fgets(readme);
}
fclose(readme);
}
// Unsupported command
else
{
fputs("Unsupported command, use help to display the manual\n", stderr);
}
}
return EXIT_SUCCESS;
}
just copy this and paste onto yours
compiled it, but still get a bunch of errors:
myshell1.c: In function ‘main’: myshell1.c:111:21: error: ‘BUFFER_LENreadme’ undeclared (first use in this function) fgets(line,BUFFER_LENreadme); ^ myshell1.c:111:21: note: each undeclared identifier is reported only once for each function it appears in myshell1.c:111:10: error: too few arguments to function ‘fgets’ fgets(line,BUFFER_LENreadme); ^ In file included from myshell1.c:8:0: /usr/include/stdio.h:622:14: note: declared here extern char fgets (char restrict s, int n, FILE *restrict stream) ^ myshell1.c:112:22: warning: comparison between pointer and integer [enabled by default] while (line != EOF){ ^ myshell1.c:114:14: warning: passing argument 1 of ‘fgets’ from incompatible pointer type [enabled by default] line = fgets(readme); ^ In file included from myshell1.c:8:0: /usr/include/stdio.h:622:14: note: expected ‘char * restrict’ but argument is of type ‘struct FILE ’ extern char fgets (char *restrict s, int n, FILE restrict stream) ^ myshell1.c:114:14: error: too few arguments to function ‘fgets’ line = fgets(readme); ^ In file included from myshell1.c:8:0: /usr/include/stdio.h:622:14: note: declared here extern char fgets (char restrict s, int __n, FILE restrict stream) ^
I copied and compiled your latest merge
k lemme fix
ok. is it due at 11.59?
here:
/*
*/
// Put macros or constants here using #define
// Put global environment variables here
// Define functions declared in myshell.h here
int main(int argc, char *argv[]) { // Input buffer and and commands char buffer[BUFFER_LEN] = { 0 }; char command[BUFFER_LEN] = { 0 }; char arg[BUFFER_LEN] = { 0 }; char cwd[BUFFER_LEN] = { 0 }; char line[BUFFER_LEN] = { 0 };
char shell[BUFFER_LEN] = { 0 };
getcwd(shell, sizeof(shell));
strcat(shell,"\\myshell");//store shells working directory
int paused = 0;
FILE *readme;
// Parse the commands provided using argc and argv
// Perform an infinite loop getting command input from users
while (fgets(buffer, BUFFER_LEN, stdin) != NULL)
{
// Perform string tokenization to get the command and argument
sscanf(buffer,"%s %s",command,arg); // Parse the commands provided using argc and argv
// Check the command and execute the operations for each command
//pause has priority, we want to check if paused or not before checking if its actually a command
if (strcmp(command,"pause")== 0 && paused != 0 && strcmp(arg, "") == 0){
paused = 1;
}
else if (paused == 0){
if (strcmp(buffer, "\n") == 0){
paused = 0;
}
}
// cd command -- change the current directory
else if (strcmp(command, "cd") == 0)
{
if (strcmp(arg,"")!= 0){
strcat(command," ");
strcat(command,arg);
system(command);
}
else{
system("pwd");
}
}
// directory listing
else if (strcmp(command, "dir") == 0 && strcmp(arg, "") == 0)
{
getcwd(cwd, sizeof(cwd)); //store cwd
strcpy(command,"cd"); //switch to cd command
strcat(command," ");
strcat(command,arg);
system(command);
system("ls"); // display all files (linux) within cwd
strcat(command," ");
strcat(command,cwd);
system(command);//cd back to stored cwd
}
//enviorment variables
else if (strcmp(command, "environ") == 0 && strcmp(arg, "") == 0)
{
system("printenv"); // again linux terminal usage
}
// clear command
else if (strcmp(command,"clr")== 0){
//system("cls"); // windows terminal usage
system("reset"); // linux terminal usage
}
// quit command -- exit the shell
else if (strcmp(command, "quit") == 0 && strcmp(arg, "") == 0)
{
return EXIT_SUCCESS;
}
// echo command -- repeat back argument then move to next line with \n
else if (strcmp(command, "echo") == 0 )
{
strcat(arg,"\n");
fputs(arg,stderr);
}
else if (strcmp(command, "help") == 0 && strcmp(arg, "") == 0){
readme = fopen("README.md", "rt");
fgets(line,BUFFER_LEN,readme);
while (line != EOF){
fputs(line,stderr);
line = fgets(line,BUFFER_LEN,readme);
}
fclose(readme);
}
// Unsupported command
else
{
fputs("Unsupported command, use help to display the manual\n", stderr);
}
}
return EXIT_SUCCESS;
}
yes due then, compile this quick and just had it in
ok. I cant hand it in though. the group doesnt dhow up on my blackboard
attach file to this comment
ill hand it in
ok
just make sure no syntax errors
cant upload files here, not allowing
email to james.morrison1@uoit.net
ok
sent
handed it in
perfect, thanks
myshell.c: In function ‘main’: myshell.c:33:26: error: ‘shellcwd’ undeclared (first use in this function) getcwd(shell, sizeof(shellcwd)); ^ myshell.c:33:26: note: each undeclared identifier is reported only once for each function it appears in myshell.c:34:18: warning: unknown escape sequence: '\m' [enabled by default] strcat(shell,"\myshell");//store shells working directory ^ myshell.c:76:15: error: incompatible types when assigning to type ‘char[256]’ from type ‘char *’ command = "cd"; //switch to cd command ^ myshell.c:95:1: error: expected expression before ‘<<’ token <<<<<<< HEAD ^ myshell.c:97:1: error: expected expression before ‘==’ token
^ myshell.c:99:9: error: invalid suffix "d1a1cd10436e5c8215baad5f44c5edf1034907" on integer constant