Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Baby's first C

Name: Anonymous 2007-07-14 22:06 ID:q/I/CZGz

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: Anonymous 2007-07-14 22:10 ID:HI14GHNJ

Use labels and goto statements.

Name: Anonymous 2007-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.

Name: Anonymous 2007-07-14 22:26 ID:R7wvjTm6

   int loop = 1;
   for (loop = 1;loop == 1; ) {

while(loop) motherfucker, do you use it?

Name: Anonymous 2007-07-14 22:35 ID:q/I/CZGz

Changing it to a while loop also worketh not.

Name: Anonymous 2007-07-14 22:41 ID:Heaven

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

Name: Anonymous 2007-07-14 22:51 ID:bKpvyNNw

>>6
this kopipe is fucking win

>>1
char textinput[] = "";
printf("Type something...\n") ;
scanf("%s",&textinput) ;

LOL BUFFER OVERFLOWS

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: Anonymous 2007-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.

Name: Anonymous 2007-07-14 23:40 ID:Heaven

This program is pretty much copypasta'd from K&R.

LOL OP PHAYULZ

Name: Anonymous 2007-07-14 23:54 ID:Heaven

>>9
you cannot be serious.

Name: Anonymous 2007-07-15 0:16 ID:Heaven

Commencing sage due to shitty code

Name: Anonymous 2007-07-15 2:15 ID:vSQxBOqi

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

Name: Anonymous 2007-07-15 2:42 ID:Heaven

>>12
THEN LEARN FIRST FAG

Name: Anonymous 2007-07-15 3:14 ID:N4RoePTj

here anon, this is how you do it

module Main where

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

Name: Anonymous 2007-07-15 3:28 ID:Heaven

haskell sucks :lol:

Name: Anonymous 2007-07-15 6:59 ID:YvN+Kocx

#include <stdlib.h>

int main() {
    system("vim");
    return 0;
}

Name: Anonymous 2007-07-15 14:25 ID:vSQxBOqi

>>13
hay be nice emo anonymous is sensitive

Name: Anonymous 2007-07-15 14:56 ID:NNEDIDJl

>>16
cp emacs vim

Name: Anonymous 2007-07-15 17:31 ID:Heaven

>>18
as in cp < emacs < vim ?

Name: Anonymous 2007-07-15 21:02 ID:UewD268G

>>18
>>19
cp? WHERE?

Name: Anonymous 2007-07-16 0:22 ID:Heaven

>>20

$ which cp
/usr/bin/cp

Name: Anonymous 2007-07-16 0:22 ID:Heaven

>>20
but it would be funnier with $ whereis cp

Name: Anonymous 2010-12-27 7:01


Don't change these.
Name: Email:
Entire Thread Thread List