For my first C project I'm trying to write a commandline text editing program. Although I'm aware of many problems with this code, I only request advice on one of them. I would like the for loop I have there to loop around where I have the continues, for example where the continue is after the text input, I want it to loop around so you can select new, save, load or help after inputting text. The way it is right now it just ends the program after one of the commands is executed without looping around at all. I'm using Dev-C++ if that makes a difference.
#include <stdio.h>
#include <string.h>
int main() {
printf("Commandline Text Editor by xxxxxx \n") ;
printf("Type help to get started \n") ;
int loop = 1;
for (loop = 1;loop == 1; ) {
char command[] = "";
scanf("%s",&command) ;
if (strcmp(command,"save") == 0) {
//save text to a file
continue;
}
if (strcmp(command,"new") == 0) {
char textinput[] = "";
printf("Type something...\n") ;
scanf("%s",&textinput) ;
printf("You typed: \n %s \n",textinput) ;
printf("What do you want to do with this text? \n") ;
continue;
}
if (strcmp(command,"load") == 0) {
//load text file
continue;
}
if (strcmp(command,"help") == 0) {
printf("Available commands are:\n") ;
printf("new, save, load, help") ;
continue;
}
else {
printf("Excuse me, wtf r u doin? Type help for a list of available commands \n") ;
continue;
return 0;
}
}
return 0;
}
Name:
Anonymous2007-07-14 22:10 ID:HI14GHNJ
Use labels and goto statements.
Name:
Anonymous2007-07-14 22:12 ID:q/I/CZGz
I tried that earlier, but when I tried to put a label in (you just type the label name with a colon after it, right?) it gave me a syntax error.
OKAY q/I/CZGz YOU FUQIN ANGERED AN EXPERT PROGRAMMER
GODFUCKIGNDAMN
FIRST OF ALL, YOU DONT FUQIN KNOW WHAT A MAN PAGE IS
SECONDLY, THIS IS /prog/ DO NOT DEMAND USEFUL ANSWERS THE WAY YOU WANT THEM TO BE
THIRDLY PROGRAMMING IS ALL ABOUT PHILOSOPHY AND ``ABSTRACT BULLSHITE'' THAT YOU WILL NEVER COMPREHEND
AND FUQIN LASTLY, FUCK OFF WITH YOUR BULLSHYT
EVERYTHING HAS ALREADY BEEN ANSWERED IN>>2 and >>4
look >>1 want my advice? get K&R and start reading it, learn from it and the example codes it has, and try to code what it advices you to (it has some "challenges")
You clearly don't know any C, but do not ph33r for it takes at least 3 years to master C. (and that is if you hurry)
Name:
Anonymous2007-07-14 23:36 ID:VPifnN/p
1) HOLY BUFFER OVERRUNS, BATMAN!
Hide the memory!
2) Unreachable code:
continue;
return 0;
wtf?
3) Lack of functions. If you think you can get away with putting your whole program into a main() function, you're doing it very wrong.
4) printf("new, save, load, help") ;
You forgot "quit", asshole.
5) if if if if else. Did you perhaps mean to do a "switch", instead? You DO know that the else block executes if the "if" statement immediately preceeding it is false, and has nothing to do with the earlier three "if" statements, right?
Though in your example this doesn't matter as all the "if" blocks force the outer loop to continue, anyway. But it still sucks.
have two while loops and the inner loop just breaks instead of continue and the second contains your options and stuff? I dont know I dont even program lol
main :: IO ()
main = do
putStr "Commandline Text Editor by xxxxxx \n"
putStr "Type help to get started \n"
cmd <- getLine
case cmd of
"save" -> return ()
"load" -> return ()
"new" -> do txt <- getLine
putStrLn $ "You typed: " ++ txt
++ "\nWhat do you want to do"
++ "with this text?"
"help" -> putStrLn $ "Available commands are:\n"
++ "new, save, load, help"
_ -> putStrLn $ "Excuse me, wtf r u doin?\n" ++
"Type help for a list of available " ++
"commands"
main