Programming :: Dividing A String Into Substrings With Three Elements In C++
Jun 23, 2011
im trying to receive a string from user, then divide it into groups of strings with 3 elements only. meaning if input is:
12345 it should give 123 and 45
123456 it should give 123 and 456
1234567 it should give 123 and 456 and 7
anyway what happens based on my code is that it works fine with first two (when it has groups of 3 elements and 2 element, and also when it has groups of all 3 elements) but for the last case (when makes groups of 3 elements and 1 group of 1 element) it shouws as "123 456 7 D"!! meaning it adds one extra character to the last element out of no where!
here is my code:
Code:
#include <iostream>
#include <conio>
struct array
{
[Code]....
View 1 Replies
ADVERTISEMENT
Oct 22, 2010
copy string a to string b and change string b with toupper() and count the chars
View 3 Replies
View Related
May 3, 2011
I've been trying to understand pthread in C a little better. So I made a simple program that takes in a string from the command line and creates a thread to print the string. I've looked online and copied the basic concepts but there are something things I'm confused about. The programs works just fine, but I have questions. Here's what I have so far.
[Code]....
One thing I'd like to know is why the 3rd argument in the pthread_create function which is my SendMessage function needs to be typecasted to a void pointer and then send the address of the function. Also as for the 4th argument, I would see typecasting to void pointer in some of the pthread examples I saw online, but in my case I'm passing a char pointer, would this be correct? In which case would I ever want to pass a void pointer?
Do I need a pthread_exit(NULL) in my main and in the SendMessage function? If so, why? I added the sleep() function so that I could let the pthread_exit function in my SendMessage function execute first. I simply saw that the online examples on pthread had pthread_exit() in both locations.
View 6 Replies
View Related
May 27, 2010
i've got certain functions now declared as static and their being used as pointers. So, moving on I then added a variable which so happened to be used in both static and non static functions. Here's some testbed code, the variable in question is 'window':
Code:
//g++ -Wall -I/usr/include/ -L/usr/X11R6/lib -lX11 -lXi -lXmu -lglut -lGL -lGLU -lm main.cpp -o run
#include <GL/glut.h>
#include <stdlib.h>
[Code]....
In short, I can't see the point of using a class to wrap all of this. Never having been taught programming i'm unsure as to the best method for structuring an application like this. Should (would you design) this initial section be a class?
View 4 Replies
View Related
Oct 16, 2010
I have a set of lines as ahown below:
Leon went to school
Leon came back from school..
Leon had dinner...
I have to replace the line containing "dinner" by a single string LUNCH...
View 2 Replies
View Related
Feb 25, 2011
I need to creates string suffixes out of a Reference string. for eg. suffixes of abcdefg will be
1)bcdefg
2)cdefg
3)defg
and so on...
create an array of pointers to point to the first few characters and then use that pointer to print the rest of the string.But when i print using the pointer i get GARBAGE values! shudn't std::cout<<ptr[w] print the string following the char it is pointing to? why do i get garbage values?
View 9 Replies
View Related
Apr 18, 2010
So if I'm given a location of a file like:
How can I just take the type of the file at the end? I know I can use strrchr() for a period to get the pointer to the period just before file type. Is there a build in string function that will just take the rest of the string from a certain point on forward in the string? I know it wouldn't be much work to make it myself, but I figured I would find out if it already existed before doing it.
View 9 Replies
View Related
Mar 13, 2010
Code:
The error is:
Code:
What I want to do is take input of ip4 as a string, convert it to an integer to add 1 to it, then reconvert it back to a string. Its not working.
My full code is:
Code:
View 1 Replies
View Related
Jan 27, 2011
I have a char*[] array:
Code:
char* myarray[] = {"Hello", "there!", "LQ"};
and I wish to use/ write a function to find the number of elements in myarray (in this case, its 3).
*equivalent of .NET's array.size() that returns number of elements in array
How do I achieve it?
View 7 Replies
View Related
Apr 27, 2010
created this array and the last two elements will not pop - phil and sylvia never get up to bat.
1#!/usr/bin/perl
2use strict;
3use warnings;
[code]...
View 3 Replies
View Related
Jul 20, 2011
I have an array with 15 elements, and I want to break it down into three columns. When the array is split into a the three elements - however on the iteration, it does not conform to that structure.
Code:
#!/usr/bin/perl -w
use strict ;
[code]....
View 13 Replies
View Related
Dec 10, 2008
I have something like this:
$arr_hash{'produce'}{'veggies'}[0] = Broccoli
$arr_hash{'produce'}{'veggies'}[1] = Cauliflower
$arr_hash{'produce'}{'veggies'}[2] = Carrots
[code]...
View 2 Replies
View Related
May 16, 2010
I am trying to learn how to include common elements on every page. At first I made the mistake of calling it ssi but I do not think that is correct in php5. I downloaded phpb3 to look at and they are not doing it that way. they do it like this.
Code...
Problem is I can not find any articles that explain it. I even looked at the php manual and did not find it. Could someone explain this or point me in the right direction.
View 1 Replies
View Related
Jul 15, 2009
For Perl I need to understand a few things. It's unlikely that anyone will be able to give me direct answers but if they could point outI'm trying to hack down an existing script http://eoylpac.org/source/eoy.pl. What I need to be able to do (in a nut shell):1. Open a database2. Read the values for each uniq id and execute a subroutine for each of those values. (The subroutine already exists in the above file 'do_pdf').
View 5 Replies
View Related
Mar 13, 2011
I have .txt.gz files that store queries made on a browser, d my job is to analyze them.The information is stored in a xml-like style.Quote:
<browser>lwp-trivial/1.41</browser>
<http_code>200</http_code>
<keywords />
[code]...
View 6 Replies
View Related
Sep 18, 2010
For a search box on my site, I want a textbox, which will let the user input the term to be searched for, and next to it I want a drop down list that'll have, for example, "Fruit" and "Vegetables" as categories to be searched within. How do I do the HTML for this? (so that the arguments to my search.php script will be eg. "search.php?text=apples&type=fruit" ? )
View 3 Replies
View Related
Oct 12, 2009
I've been given a custom-made string class which handles string, wstring and bstr. It has a number of methods and assignment operators to convert to and from different types. The app I work on compiles happily in VS6 and VS2008, but when trying to compile in Redhat (version 4.1.1 in Redhat 5.0)
[code]....
View 4 Replies
View Related
Nov 11, 2010
I have the following two type of strings1: A/D2: A/C/DI am trying to write a subroutine to check whether all of the letters in string 1 appears in string 2. If yes, return true. If not, return false. In the above example, all the letters (A and D) in string 1 are also present in string 2, so I return true.
View 4 Replies
View Related
Mar 29, 2010
Is there some way to access HTML elements via javascript through some internal ID?
For instance, given a form like:
Code:
<form name="myForm">
<input type="text" />
<input type="text" />
[Code]....
I think I've seen some way to do this before but I'm not certain
View 4 Replies
View Related
Oct 12, 2010
How can I declare an array with the number of elements is larger than 2^32 ?
View 2 Replies
View Related
Apr 30, 2010
...and returning the index of the found element in its array.
I have:
for ((i=0; i < ${#array1[@]}; i++)); do
# Read each line of the file test
if [[ $(eval "sed -n '$(($i+1))'p test") == *${array2[0]}* ]]
stuff
I want to find the index of the found substring in array2 and only if it isn't found, move on to the next element of array2. I don't know the size of array2 so that [0] has just got to go.
View 14 Replies
View Related
Apr 13, 2010
I'm trying to make a combo box which should have elements dynamically taken from a database. I've an Exam Table,and it has columns Sno,Ename,Month,year. i need the combobox to list to the elements that are present in Ename.
i read some things in the web and tried that out in the netbeans. it said to rightclick the combobox and set bind ->elements and bind->selecteditem. But i'm not sure how to set the binding expressions inorder to get the required list in the combobox.
View 1 Replies
View Related
Feb 24, 2010
When I parse a XML file, should I rely on the order of elements?
For example say we have:
Should I rely on the above order?
Would the following still be valid:
I'm trying to find out if a well formed XML document should have an ordered structure, or if it's still valid XML if it has no order.
View 7 Replies
View Related
Jul 5, 2010
I want to declare an array with fixed size and initialize all the elements to zero. i want all elements of x to be zero and i dont know how to specify the size of array. also i have problem in comparing values in loops. my script is as follows:
i=0
let k=0
declare -a x
for U in ${S[@]}
do
for (( T=1276082023 ; $T -le 1276082139 ; (( T++ )) ))
[Code]...
View 8 Replies
View Related
May 10, 2011
I got requirement to find the difference between two strings and write the difference to new file by comparing the substrings separted by commas
Below mentioned is an example of requirement
String1 --> ABC,DEF,GHI,JKL
String2 --> MNO,ABC,XYZ,DEF
In String1 and String2 the substrings are separted by commas. The substrings which are common between String1 and String2 are ABC,DEF this common substrings has to be written to a file say common.txt ( having the text ABC,DEF). And the substrings GHI,JKL in String1 which are not present in String2 has to be written to another file say String1Extra.txt (having the text GHI,JKL). In the same way the substrings MNO,XYZ from String2 which are not present in String1 has to be written to another file say String2Extras.txt(having the text MNO,XYZ) .
View 1 Replies
View Related
Mar 26, 2011
Do I have the convert the int to a string using stringstream then convert the string to a char? or is there a more direct way?Also is there a way to tell the length of a int?
View 5 Replies
View Related
Apr 12, 2011
I know Ubuntu can do amazing things, but I was wondering if it can use different Internet connections for different websites.
The Setup: We have 1x unshaped ADSL connection at 4MBPS (fastest available) that's used for office related things, Skype, General browsing etc. We have another ADSL connection, this time shaped and running at 4MBPS, I want to send all requests to facebook, twitter and downloading sites like fileserve, filesonic, hotfile etc. to the shaped connection. Can iptables be used to do this? The unshaped ADSL router is connected to eth0 and has an IP of 192.168.0.1 the shaped ADSL router is connected to eth2 and has an IP of 10.0.2.1 Local lan is connected to eth1 and has a range of 192.168.1.0/24 Can iptables send a certain webpage (*.facebook.*) to eth2 and other pages (*.google.*) to eth0 ?
View 3 Replies
View Related
Oct 6, 2010
Trying to move from squeeze to unstable -- my downloads add up to some 700 M or so.So I am trying to batch the upgrade:Some of the big-fellas are openoffice and texlive:So I didsudo aptitude hold '?name(openoffice)'sudo aptitude hold '?name(texlive)'Is that fine or are there some pitfalls to this?
View 5 Replies
View Related
Nov 24, 2010
I have a serial port program which is reading a string .if(read(readfd,sResult,1)>0)where sResult is unsigned char sResult[10];if sResult is array of 10 then iam getting string perfectly but if iam making sResult only as unsigned char I am getting NULL value CODE BELOW
Code:
unsigned char sResult;
main()
{
readfd = open("/dev/ttyUSB0", O_RDONLY);
if (readfd == -1)
{
perror("READ: open_port: Unable to open /dev/ttyUSB0-
[Code]...
View 2 Replies
View Related
Sep 13, 2010
I want normal substring of a string that actually is a url as follows
SITEURL/main.php?page=122&type=download_file&fileID=9&user Id=user1&org=org1&mainmenu=main1&submenu=sub1
What I want is a substring like below
org1_user1_main1_sub1
View 5 Replies
View Related