Jump to content


Photo

C/C++ Programming: String Parsing


  • Please log in to reply
9 replies to this topic

#1 linuxuser

linuxuser

    Honourable Member

  • WNSO Addict
  • PipPipPipPip
  • 1,147 posts

Posted 11 June 2004 - 04:01 PM

Problem: Write C/C++ code to parse a given sentence ( which is called String in C/C++ world ) "Test1:Test2:Test3" by character semicolon ':'.
Solution should be:
First String: Test1
Second String: Test2
Third String:Test3

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void parse( char* buffer, char ch )
{
char firstString[100], secondString[100];
int address1,address2, strlen;
char* pdest,*predest;
pdest = strchr( buffer, ch );
if( pdest != NULL ){
address1 = (int)buffer;
address2 = (int)pdest;
strlen = address2 - address1;
if( strlen <= 0 ) { printf("Oooopps fuked up."); return;}
strncpy( firstString, buffer,strlen );
firstString[ strlen ] = 0;
printf("First String:%s\n", firstString );
pdest++;
predest = strchr( pdest,ch);
if( predest != NULL){
address1 = (int)pdest;
address2 = (int)predest;
strlen = address2 - address1;
if( strlen <= 0 ) { printf("Ooooops fuked up."); return;}
strncpy( secondString, pdest,strlen );
secondString[ strlen ] = 0;
printf("Second String:%s\n", secondString );
//Extract the last string now
predest++;
printf("Third String:%s\n", predest );
}
}
}


void main( void )
{
parse("Test1:Test2:Test3",':');
}

Edited by rs_1915, 11 June 2004 - 04:03 PM.

:)

#2 Bohara

Bohara

    Honourable Member

  • WNSO Addict
  • PipPipPipPip
  • 666 posts

Posted 21 July 2004 - 08:31 PM

QUOTE (rs_1915 @ Jun 11 2004, 04:01 PM)
Problem: Write C/C++ code to parse a given sentence ( which is called String in C/C++ world ) "Test1:Test2:Test3" by character semicolon ':'.


Its so intresting RS g .. . .

#3 Bohara

Bohara

    Honourable Member

  • WNSO Addict
  • PipPipPipPip
  • 666 posts

Posted 21 July 2004 - 09:06 PM

I'm so glad to see RS g here. . . anyway C is one of the most important software to devlop to hardware. So RS g i've made one simple program about using one diode where i've used max 10v with 2-0e+00 time constant in graphic mode. U can find here the specially current with fordward bios. So anyone u can make RC/RLC circuit to using C in graphic mode.


#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <graphics.h>
#include <math.h>
#include <conio.h>


#define PI 3.14159

typedef char string[BUFSIZ];
void Diode_response();
void Diode_grapic();
void makegraph();
void box_draw();

float ID[500];


int main(void)
{
char ch;
Diode_response();
printf("\n \n Do u want to open in Graphic mode[yes:y]? or no[no=n)?");
ch=getch();
if(ch=='y')
{
Diode_grapic();
}
ch=getch();
if(ch=='n')
return(0);
}


void Diode_response()
{
int i;
float k,VD;
k=11600.;
for(i=1;i<300;i++)
{
VD=(float)i/500.;
ID[i]=(exp(k*(VD)/(27.+273.)))-1;
}

}

void Diode_grapic()
{
int g_driver, g_mode,i;
int P_time,P_data,x_pixsel,Y_axis,Max_point,P_data_1;
float Y_max,X_max,Vc,X_point,Vr1,Vc1;

Max_point=500; //최대 pixel point

detectgraph(&g_driver, &g_mode);
initgraph(&g_driver, &g_mode, "..\\..\\bgi");
cleardevice();
box_draw();
outtextxy(200,10,"DIODE Timeconstant response");

// Vr, Vc bata current measuring

for (i=1;i<300;i++)
{
setcolor(14);
if(ID[i]/10000.>240.) break;
line(i+50,300-(int)(ID[i]/10000.),i+51,300-(int)(ID[i+1]/10000.));
}


// 축 스케일 계산
Y_max=10; //y max value

//y축 스케일

for(i=0;i<6;i++)
{
gotoxy(3,4+i*3);
printf("%2.1f",Y_max-(Y_max/5)*i);
}

//x축 스케일
X_max=2;

for(i=0;i<12;i+=2)
{
X_point=i*X_max/10;
gotoxy(6+i*6,20);
printf("%1.1e",X_point);
}

getch();
closegraph();
}


void box_draw()
{
int i;
//x 축으로 선 긋기
setcolor(8);
for(i=50;i<550;i+=10)
{
line(i,50,i,300);
}
setcolor(7);
for(i=50;i<550;i+=50)
{
line(i,50,i,300);
}
// y 축으로 선 긋기
setcolor(8);
for(i=50;i<300;i+=5)
{
line(50,i,550,i);
}
setcolor(7);
for(i=50;i<300;i+=50)
{
line(50,i,550,i);
}

// 사각형 그리기
setcolor(10);
rectangle(50,50,550,300);
}

//(When u check this program, u've to change in graphic mode ur c complier)

Edited by Bohara, 21 July 2004 - 09:08 PM.


#4 linuxuser

linuxuser

    Honourable Member

  • WNSO Addict
  • PipPipPipPip
  • 1,147 posts

Posted 04 November 2004 - 05:36 PM

Bohara,,i didnot even see ur post until today..wow ( after so many months),,i will definitely need to check out ur code,,and i will change the graphic mode of my computer before i try it. thanks..post some more and give info on any electronic projects u r working on.
:)

#5 Triene

Triene

    Honourable Member

  • WNSO Addict
  • PipPipPipPip
  • 1,088 posts

Posted 15 February 2005 - 04:21 PM

Khai ke ke...someone give me tele lesson please. : )

#6 Andriuxa

Andriuxa

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 20 February 2005 - 03:26 PM

Hi guys,

help me a little...I've got a program and i don't lnow how to make it.
The program is:
Enter a sequence of numbers (it can be negative(with -)) which end will be marked 0.Print the amount of numbers,which begins with same numbers.For example: 2334,3453,121,6456 the answer will be 3.

Thanx a lot.

Andrew

#7 Andriuxa

Andriuxa

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 20 February 2005 - 04:01 PM

Hi guys,

help me a little...I've got a program and i don't lnow how to make it.
The program is:
Enter a sequence of numbers (it can be negative(with -)) which end will be marked 0.Print the amount of numbers,which begins and ends with same number.For example: 2334,3453,121,-6456 the answer will be 3.

Thanx a lot.

Andrew

I've made a mistake there...sorry.

Edited by Andriuxa, 20 February 2005 - 04:04 PM.


#8 linuxuser

linuxuser

    Honourable Member

  • WNSO Addict
  • PipPipPipPip
  • 1,147 posts

Posted 21 February 2005 - 02:20 PM

help me a little...I've got a program and i don't lnow how to make it.
The program is:
Enter a sequence of numbers (it can be negative(with -)) which end will be marked 0.Print the amount of numbers,which begins and ends with same number.For example: 2334,3453,121,-6456 the answer will be 3.

Andriuxa,
i have some psuedocode for u,,see if u can write code from there, if not i will help u.

//Global variable
totalNumofSameNumber = 0
do {
firstNumber = 0
lastNumber = 0
while ( entry is not 0 ){
Enter a number
determine this is the first number or not,, if it is remember the number
firstNumber = this number
determine this is the last number or not, if it is last number, compare
lastNumber = this number
if( firstNumber == lastNumber ) totalNumofSameNumber++;
}

Write next sequence of numbers. Y or N?
while ( write next sequence == Y )
}


:)

#9 Andriuxa

Andriuxa

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 21 February 2005 - 03:49 PM

hm...interesting but I don't understand sad.gif
Friends told me to do this program using procedure (string and massive),but I don't know how to work with string :/ I've read about it,but... sad.gif
I am 1 course student...it is a little bit difficult for the first time to understand everything at one time...and a lot of task to do...need more time :/

Tell me how to write or write it if you can,please.
Thanks.

#10 alpa

alpa

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 07 March 2007 - 08:50 AM

Hi,

You have a very cool Forum here꿯oved the content.
I have a question..
- 밪eeking experienced programmer with following skills: strong browser UI background, specifically in JavaScript, AJAX, CSS, HTML. Also must have good system & software design skills, e.g. OOP. C++/C knowledge a plus

I came across this site called Myndnet.com where u get paid if u answer this question.
It뭩 a platform for people to buy and sell Technology related information. Good money for people like us in the IT domain.
Here the link http://www.myndnet.c...amp;channel=A63

Sign up is free꿤heck it out
You can contact me at my id here for more questions : barot.alpa@gmail.com

Cheers smile.gif
Alpa





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users