LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-09-2003, 01:34 PM   #1
Genjix
Member
 
Registered: Oct 2003
Location: Pico
Distribution: SUSE 9.1
Posts: 83

Rep: Reputation: 15
c++ [Char serch + Destroy]


Im making some code to take input from cin and basically search for the first string in a '
Thing is if I put any characters before it, it includes extra characters on the end (which varies depending on how far across the screen when the first ' is.
Here is my messy (unoptimized) code.

#include <iostream>
#include "scrf" //basically has functions getch() and clrscr()
#define TRUE 1
#define FALSE 0


typedef short unsigned int sint;

//function declarations
sint quit( void );
void takinchar( int justachar[] );

//define constants - using const not define
const sint cmdl = 100; //all string lengths


int main()
{
char line[cmdl] , prog[cmdl];
sint strc = FALSE , progx = 0;

std::cin >> line;
for ( sint chrl = 0 ; chrl <= cmdl ; chrl++ )
{
if (strc == TRUE)
{
prog[progx] = line[chrl];
progx++;
}


if (line[chrl] == '\'')
{
if (strc == FALSE)
strc = TRUE;
else if (strc == TRUE)
{ prog[chrl-1] = '\0';
break; }
}
}


std::cout << "\nhere it is :" << prog << ":";

takinchar( prog );


return quit();
}

sint quit( void ) //Im QUITTING I AM
{
std::cout << "\nPress any key to exit";
getch();
std::cout << "\n\a";

return 0;
}

void takinchar( int progad[] )
{
//play with char here.

}


Also I know I cant return a string from a function, so who would I go about returning the adress of the string( references? ).

Thanks
 
Old 11-09-2003, 02:23 PM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,556

Rep: Reputation: 140Reputation: 140
http://www.cplusplus.com/ref/#libs

look at string.h or cstring

maybe this will help, good luck

Last edited by j-ray; 11-09-2003 at 02:24 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C pointers confusion - char ** = char [][] ?? saravkrish Programming 12 12-02-2004 10:06 AM
C Problem---convert char to char* totti10 Programming 11 11-06-2004 11:32 AM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM
convert from char* to unsigned char* D J Linux - Software 2 02-20-2004 04:09 AM
Copy a char* to another char* sathyan Programming 8 07-24-2003 06:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration