Thread: Porting an input function from linux to windows

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    5

    Porting an input function from linux to windows

    Code:
    void input(char *s, char *n)
    {
    	char *ptr;
    	int c;
    	
    	ptr = s;
    	*n = *ptr = '\0';
    	do {
    		c = getchar();
    		switch(c) {
    			case '\010':
    				if(ptr > s)
    					--ptr;
    				break;
    			case '\030':
    				ptr = s;
    				break;
    			case '\n':
    				break;
    			case ' ':
    				ptr = n;
    				break;
    			default:
    				if(c >= ' ')
    					*ptr++ = c;
    			}
    		*ptr = '\0';
    	} while(c != '\n' && ptr < s + BUFFSZ);
    }
    this is the function i wrote to get input from the user. when i compiled it with gcc and ran it with bash it wrote the first characters to s and everything after the last space to n. when i compiled it with mingw and ran it with cmd it kept writing what was in the buffer after each space to s every time it was called. so if i typed in 3 "characters like this" in bash it would make s equal to "characters" and n equal to "this", whereas in cmd it writes "characters" to s, then "like" to s when it's next called, then "this" to s when it's next called.

    does anybody know how i could rewrite this function in a way that cmd supports?

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    What this function is supposed to do and what does its arguments mean?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    5
    it takes the first characters before the initial space (if there is one) and places it into the first variable passed to the function, then all of the characters following the final space are placed in the second variable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can't compile library
    By pjs111 in forum C Programming
    Replies: 16
    Last Post: 05-24-2010, 01:42 PM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM