locked
Help with C on a text entry, Please help! RRS feed

  • Question

  • User1365171777 posted

    I am trying to make a black screen that lets me enter a line of text, and like when a put choice "a" it loads a wmt.txt in plain

    C  I have want through hours on google and cant figure it out please help!

    Wednesday, January 14, 2009 12:04 PM

All replies

  • User810302116 posted

     Hi,

    You mean you want to simulate Dos prompt on the web?

    Regards

    Wednesday, January 14, 2009 12:51 PM
  • User1365171777 posted

    not qite more like an app that looks kinda like a dos that runs in a dos window, that lets me input a line.

    Wednesday, January 14, 2009 2:54 PM
  • User1365171777 posted

    I have found a somewhat help to my problem.

     

    1. #include <stdio.h>
    2. #include <string.h>
    3.  
    4. int main()
    5. {
    6. char text[20];
    7. fputs("enter some text: ", stdout);
    8. fflush(stdout);
    9. if ( fgets(text, sizeof text, stdin) != NULL )
    10. {
    11. char *newline = strchr(text, '\n'); /* search for newline character */
    12. if ( newline != NULL )
    13. {
    14. *newline = '\0'; /* overwrite trailing newline */
    15. }
    16. printf("text = \"%s\"\n", text);
    17. }
    18. return 0;
    19. }
    <TEXTAREA style="WIDTH: 1049px; HEIGHT: 349px" class=code wrap=off cols=112 readOnly itxtvisited="1">#include <stdio.h> #include <string.h> int main() { char <strong class="highlight">text</strong>[20]; fputs("enter some <strong class="highlight">text</strong>: ", stdout); fflush(stdout); if ( fgets(<strong class="highlight">text</strong>, sizeof <strong class="highlight">text</strong>, stdin) != NULL ) { char *newline = strchr(<strong class="highlight">text</strong>, '\n'); /* search for newline character */ if ( newline != NULL ) { *newline = '\0'; /* overwrite trailing newline */ } printf("text = \"%s\"\n", <strong class="highlight">text</strong>); } return 0; }</TEXTAREA>
    1. <TEXTAREA style="WIDTH: 4px; HEIGHT: 11px" class=code wrap=off rows=1 cols=2 readOnly itxtvisited="1">#include <stdio.h>#include <string.h> int main(){ char text[20]; fputs("enter some text: ", stdout); fflush(stdout); if ( fgets(text, sizeof text, stdin) != NULL ) { char *newline = strchr(text, '\n'); /* search for newline character */ if ( newline != NULL ) { *newline = '\0'; /* overwrite trailing newline */ } printf("text = \"%s\"\n", text); } return 0;}#include <stdio.h> #include <string.h> int main() { char <strong class="highlight">text</strong>[20]; fputs("enter some <strong class="highlight">text</strong>: ", stdout); fflush(stdout); if ( fgets(<strong class="highlight">text</strong>, sizeof <strong class="highlight">text</strong>, stdin) != NULL ) { char *newline = strchr(<strong class="highlight">text</strong>, '\n'); /* search for newline character */ if ( newline != NULL ) { *newline = '\0'; /* overwrite trailing newline */ } printf("text = \"%s\"\n", <strong class="highlight">text</strong>); } return 0; } </TEXTAREA>
      It could use some touch ups but I found it here http://www.daniweb.com/tutorials/tutorial45806.html a few more hours of google never hurt anyone in the end :)
    Wednesday, January 14, 2009 5:34 PM