I need to make a simple command line. I have some code but it doesn't work.
char i[128];
char *inp;
inp = i;
while(1)
{
puts("SeaOS 1.0~>");
gets(inp);
if (inp == "yo")
puts("wazzup\n");
}
Can you help?
Command line stuff & issues
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
Command line stuff & issues
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
of course!!!!!!! Thanks!!!!!!!!!
.................................but I dont have a strcmp function and I have no idea how to write one...........could you help??
.................................but I dont have a strcmp function and I have no idea how to write one...........could you help??
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
This is a quick implementation, Assuming a few other things work in your OS.
Hope that helps..
(BTW this is kinda how it could be done on any other standard system..That has fgets and stdin support anyway.. )
From this you should be able to see how to use what your OS calls "gets" instead..
Code: Select all
int strlen(const char *s1) {
int i = 0;
while(*s1) {
i++;
++s1;
}
return i;
}
int strcmp(const char *s1, const char *s2) {
int i;
if(strlen(s1) != strlen(s2)) {
return 1;
}
for(i = 0; i < strlen(s1); i++) {
if(s1[i] != s2[i]) {
return 1;
}
}
return 0;
}
(BTW this is kinda how it could be done on any other standard system..That has fgets and stdin support anyway.. )
Code: Select all
#include <stdio.h>
int main(void) {
char inp[128];
while(1) {
printf("SeaOS 1.0~> ");
fgets(inp, sizeof(inp), stdin);
inp[strlen(inp) - 1] = '\0';
if(strcmp(inp, "yo") == 0) {
printf("wazzup\n");
}
}
return 0;
}
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
Thanks you guys, it really helped!
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io