C/C++ :: Parsing String Data Separated By Pipe Delimit

Mar 7, 2014

i tried to parse the string data seperated by Pipe('|') delimiter, here i am getting some error.Please find the below code.

[char* getData(){
char* string = "1355|||250|New";
char* tok1[10],tok2[10],tok3[10],tok4[10],tok5[10];
sscanf(string,"%[^'|'],%[^'|'],%[^'|'],%['^|'],%s",tok1,tok2,tok3,tok4,tok5);
printf("%s %s %s %s %s",tok1,tok2,tok3,tok4,tok5);
}]

I want to print the Value 250 in my string, but it was displaying some garbage values.

View 1 Replies


ADVERTISEMENT

C++ :: Reading In Space Separated Versus Comma Separated Files

Jul 30, 2014

I just wrote a code that reads in a text file called "policies.txt" which looks like this:

Pol1 M N 20 100000 1 .04 99
Pol2 F S 30 100000 1 .05 99
Pol3 M S 72 750000 1 .03 99
Pol4 F N 45 1000000 1 .05 99

This works perfectly fine, but what if I want each element of the table to be separated by commas. For example:

Pol1,M,N,20,100000,1,.04,99
Pol2,F,S,30,100000,1,.05,99
Pol3,M,S,72,750000,1,.03,99
Pol4,F,N,45,1000000,1,.05,99

or better yet, what if I want it to not matter whether the columns are separated by commas or spaces? is there any way to do this? If there is no way to read in both comma-separated and space-separated elements simultaneously then I would prefer just comma, rather than the space separated which my code is able to read now. What modifications would I have to make to my code to make this work? This is my code to reference.

double ratesmn[86] = {
#include "MaleNonSmoker.txt"
- 1
};
double ratesms[86] = {
#include "MaleSmoker.txt"

[Code] ....

View 4 Replies View Related

C/C++ :: Reading Data In A File Separated By Commas

Feb 14, 2015

I have a file with data in lines separated by commas and im trying to print out specific lines and specific parts of data from that line. I need to isolate lines where the first column of data reads '$CPGAR' and print out specific data columns.When I print out the strings I get random data and my strcmp to isolate lines isnt working? Im very new to this, heres a sample of my program:

while (!feof(gpsH)) {
char word1[10],word2[10],word3[10],word4[10],word5[10],word6[10],word7[10],
word8[10],word9[10],word10[10],word11[10],word12[10],word13[10];
char a[6] ="$CPGAR";
/* read data line */
fgets(gpsS,10,gpsH);

[Code]...

View 3 Replies View Related

C :: Reading In Comma Separated Numbers From A Data File

Apr 18, 2013

I am attempting to read in a file that has 4128 sets of 21 numbers separated by commas and write it into an array. I now know that in order to use fseek, I have to make my array a character array, but I need my function to read in decimals (ex: 0.172635). I'm reading in

0.102598,0.000000,0.000000,0.000000,0.000000,0.307 793,0.000000,0.410391,0.102598,0.000000,0.102598,0 .102598,0.000000,0.000000,0.102598,0.102598,0.8207 83,0.000000,0.000000,0.000000,0.000000

and keep getting numbers like 48 49 50.

Code:

void CSread(char filename[100], char array[22], char array2[22], unsigned int arraysize)
{
char genename[32];
double temp = 0;

FILE *CSfile;
CSfile = fopen(filename, "r");
");

[code].....

View 8 Replies View Related

C# :: Parsing A String In Double Quotes From A String?

Feb 2, 2015

So imagine you have this string:

"somedata here "some data here" some more data here"

I need to parse this:

somedata here "some data here" some more data here

I tried to do it with Regex and was capable of parsing

[0] = somedata here
[1] = some data here
[2] = some more data here

Here is my current code:

string Buffer = string.Empty;
foreach (Match match in Regex.Matches(strLine, "".*?""))
Buffer = match.ToString();

View 6 Replies View Related

C++ :: Parsing Data From Text File?

Aug 26, 2014

Requirements in filtering the text file.

1. first my professor required me NOT to change the MAIN function(because he made it)

2. I have to make 3 getlogs() STRING FUNCTIONS:

a. string getlogs(); - accepts no paramters, SHOWS ALL THE CONTENTS OF TEXT FILE
b. string getLogs(const string & a); - accepts 1 parameter -SHOWS ONLY THE LINE WHICH CONTAINS THE SPECIFIED DATE FROM MAIN FUNCTION which is "2014-08-01"
c. string getLogs(const string & b, const string & c); - accepts 2 parameters, SHOWS ONLY THE LINES FROM THE DATE START to DATE END specified at THE MAIN FUNCTION which is date start-"2014-08-01";DateEnd = "2014-08-10";

3. all COUT should be in the MAIN FUNCTION

TEXTFILE CONTAINS:
2014-08-01 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-03 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-04 06:13:14,Name,4.5,CustomUnit,CustomType

[Code] .....

my codes so far:

//MAIN
#include <iostream>
#include <string>
#include <fstream>
#include <dirent.h>

[Code].....

View 1 Replies View Related

C++ :: Parsing Through Large Data Sets

May 30, 2013

So I'm attempting to write a program that will parse through a large file (genome sequences) and I'm basically wondering what options I should consider if I wanted to either:

a) store the entire genome in memory and then parse through it
b) parse through a file in small portions

If I go with "a", should I just read a file into a vector and then parse through it? And if I go with "b" would I just use an input/output stream?

View 5 Replies View Related

C# :: Parsing String Into IP Address

Oct 1, 2012

So im trying to parse a string into a Ip Address but i have a problem, the IPAddress.Parse method only works for ipv4 address's how do i parse ANY Ip address into a string, if i use the IPaddress.Parse method on my public(remote) IP it throws an exception but on ipv4 local ip it doesn't how do i parse ANY ip address the user inputs as a string as an Ip Address?

View 5 Replies View Related

C++ :: Parsing String To Contain Inputted Int

Sep 10, 2014

I have been here for almost 3 months looking for answers in my C++ problems.here's some type of code for this.

cout << "Enter value of x: " << endl; //Let's say 5.
cin >> x;
cout << "Enter equation: "; //Let's say x+1
cin >> equation;

Then the program analyzes that this character "x" has an initial value of 5.I already have the parser for the equation functions (+,-,*,/)This is the only thing lacking. Is there some type of function that i missed?

View 6 Replies View Related

C :: Parsing String And Capturing In Variables

Nov 3, 2013

I have an input file that contains any number of lines. Each line will follow the same structure. There will be 5 fields, separated by 4 commas. Fields 1 and 3 will be single characters, fields 2,4,5 will be integers. Example:

<A, 123, B, 456, 789>

I need to iterate over each line, parse out the fields, and capture each field value into a separate variables.

header file: Code: #include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>

[Code]....

I've used similar code to this before, but this time I'm getting the dreaded pointer from integer error on my strtok lines:

warning: passing argument 2 of 'strtok' makes pointer from integer without a cast'

View 2 Replies View Related

C :: Parsing Tokens In File Lines Into A Linked List Of Data

Sep 20, 2013

I have been attempting to store mathematical functions in a file by parsing them into a linked list with a variable sized char ** array as my storage device. I have ran into problems with the memory management detail. The program crashes before output is flushed to the console, so printf() wasn't a debugging option. Neither is my actual debugger, since it seems to get a SIGTRAP every time. I have my warnings turned all the way up, but no errors or warnings are appearing. The part I know works is the actual code that opens the file and gets a line from the file. As far as the two functions that implement the linked list, that is most likely where the problem lies. My current attempt is basically to store the size of the dynamic array in the structure and keep resizing it until there are no more tokens. Then I will store the number of elements of the array in the structure and move on to the next node.

Here is my text file I use :

Code:
sqrt( 25 ); pow( 6 ); sin( 2 );
pow( 4 ); tan( pow( 2 ) ); Main.c :

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct file_data

[Code]...

View 7 Replies View Related

C++ :: Parsing String To Recognize Trigonometric Functions

Sep 14, 2014

How do I create a function that can understand trigonometric functions?

Examples:

if I am to input: x^2 + sin(x)

The program will understand the the value between parenthesis preceded by a string "sin" will be computed as the sine of x. of any function in case.

I have the program here.

#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
using namespace std;
enum types { DELIMITER = 1, VARIABLE, NUMBER }; //DEL = 1; VAR = 2; NUM = 3.
class analyzer {

[Code] .....

View 9 Replies View Related

C++ :: Reading Specific Input Syntax - String Parsing

Apr 21, 2013

I need reading a specific input syntax.

something like

<Input> :: R C <Content>

3
3

.3. .15 9.2
.1. ..6 ...
6.5 7.. ...

... .5. ..9
4.7 .8. 1.6
9.. .6. ...

... ..1 7.4
... 6.. .9.
5.1 49. .3.

View 2 Replies View Related

C :: Parsing Binary Data File By Casting A Buffer - Accessing Double From Struct

Jan 4, 2014

I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.

Code:

typedef struct InvoiceRow {
uint INVOICE_NUMBER;
...
double GROSS;
...
char VAT_NUMBER[31];
} InvoiceRow;

If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...

Code:

typedef struct example {
double d;
}

example;
example *blah = (example*)row->GROSS;
printf("%f", blah->d);

View 7 Replies View Related

C/C++ :: How To Get CTRL Z To Close A Pipe

Nov 9, 2012

My 'c' program reads each line of a .txt file, makes a few changes and then outputs the line of text (which are names). I want the contents to be sorted and did not want to bother writing my own sort. The program runs in a command prompt from inside a batch file for example:

sort | makelist.exe BluRay1.txt > sorted.txt
sort | makelist.exe Dvd1.txt >> sorted.txt
..etc..

I have to supply a ctrl-z manually to close the piping. I tried the following which did not work.

buffer[0] = 26;

printf("%c",buffer[0]);
//printf("^(z)");
fclose(stdout);
fclose(stdin);

I never got the above to work so I am avoiding piping and just do a redirect instead.

makelist.exe dvd1.txt > unsorted.txt
makelist.exe dvd2.txt >> unsorted.txt
sort < unsorted.txt > sorted.txt

..etc.

Just wondering if I could have gotten the ctrl-z thru the pipe using "C".

View 2 Replies View Related

C/C++ :: Infinite Loop While Reading From Pipe?

Oct 31, 2014

Why I have an infinite loop when reading from a pipe?

i = 0;
while(i < 10) {
test_value = read(pipe3[READING], &message, sizeof(struct MESSAGE));
printf("test_value is %d
", test_value);
//printf("Entering infinite loop

[code]....

View 10 Replies View Related

C++ :: Restore Keyboard Stdin After Reading From Pipe?

Apr 25, 2014

I use the following code segment to read and output the text piped to a program. If there is no piped text, the code segment is skipped and then the program continues. What I need to do is restore stdin to the keyboard after reading from the pipe. I use the PeekNamedPipe() and ReadFile() because reading from stdin blocks until it has something, and I don't want that to happen. After reading from the pipe, the program begins to execute, and the main loop can be paused and it prompts for a command. I just can't figure out how to restore input to the keyboard. Obviously the platform is Windows.

char char_buffer[1024];
DWORD bytes_read;
DWORD bytes_avail;
DWORD dw;
HANDLE stdin_handle;
bool is_pipe = false;

[code]....

View 4 Replies View Related

C/C++ :: Combing While Loop Read With Creating A Pipe

Oct 30, 2014

I have this if block that is supposed to be creating a pipe then forking and I would like to combine the while loop below it with it. How would I do that?

p = pipe(pipe1);
if (p < 0) {
printf("pipe error");
exit(0);
} else {
printf("successful pipe1 = %d",p);

[Code].....

I have trying to read this documentation but don't understand it. [URL] ....

View 1 Replies View Related

C++ :: Create Process And Assign Pipe Terminal Like Stoudt

May 30, 2014

I have study that create a pipe and set a terminal of this pipe like a stdout of a process is a way to implement inter process comunication, but how can i do it in c++?

View 2 Replies View Related

C++ :: Sending Dynamic Allocated 2D Array Over Named Pipe Between 2 Executable

Oct 6, 2014

Im writing a scientific software where I like to sent a 2D array (5x4) over a named pipe from a server to a client. When im sending a static array (i.e., double res[5][4];), all goes fine and it works perfect, but when I allocate a dynamic array, it provides some nonsense numbers at the client side. I feel it might be caused because I point to a memory that cannot be shared through a pipe. Am I right and how can I pass the dynamic allocated array itself over the pipe.

//Server program

// Create a pipe to send/receive data
HANDLE pipe = CreateNamedPipe(
"\.pipemy_pipe", // name of the pipe
PIPE_ACCESS_DUPLEX, // 2-way pipe -- send and read
PIPE_TYPE_BYTE, // send data as a byte stream
1, // only allow 1 instance of this pipe
0, // no outbound buffer

[Code] .....

View 2 Replies View Related

Visual C++ :: Writing To Named Pipe Coming From A Service (session 0) Without Admin Rights

Dec 9, 2014

I'm trying to write to a named pipe created by a service, as we all know the session 0 isolation implemented in vista and forward makes this task a bit complicated.

well at this point i managed to make almost all to work but my real problem comes when i try to write on the named pipe from my GUI application with no administrator rights

If i run the GUI application with admin rights it works 100% but, I don't need that application to require the user admin rights and for security reasons i rather to leave it without admin...

so i started my research and i found that there is a way to achieve this by calling CreateNamedPipe() with a low integrity security attributes...

well how to implement but i finally made it, the problem is that it gets worse than passing null security attributes, it works with admin rights with NULL security attributes, but when i pass the low integrity security attributes it gives "access denied" even when using admin rights, so i guess im passing the wrong security attributes but how to manually create the security descriptor string.

This is the code:

Service (session0) SERVER

Code:
DWORD WINAPI PipeThreadRSVS(void* pParameter){
LPTSTR _PIPE_NAME = "\.pipeRSVHPipeIn";
bool Break=false;
char Received_Buffer[BlockSize+16];
DWORD BytesRead = 0;

[Code] ....

View 2 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C++ :: Reading Names In Array Separated By A Comma

Jul 7, 2013

I'm trying to read names separated by a comma using array.

For example, the expected input would look like the following:

Juila,Francisco
Adams,Wong

I know you can use getline function and set the delimiter to comma. So like ....

getline(cin, lastName, ','); getline(cin, firstName);

But the program only read the last name and ignore the firstname.

View 1 Replies View Related

C++ :: Order Numbers By Size Separated By Commas

Aug 13, 2014

Write a program that prompts the user to enter three integer values, and then outputs the values in numerical sequence separated by commas.

So, if the user enters the values 10 4 6, the output should be 4, 6, 10.

If two values are the same, they should just be ordered together.

So, the input 4 5 4 should give 4, 4, 5.

Code:
#include "std_lib_facilities.h"
int main()
{
cout << "Enter three integers, separated by space: ";
int a, b, c, temp1 = 0, temp2 = 0;
cin >> a >> b >> c;

[Code] ....

My first solution has a bug, so here's the corrected solution, written using only features I have learned in the first three chapters:

Code:
#include "std_lib_facilities.h"
int main()
{
cout << "Enter three words, separated by space: ";
string a, b, c, temp;
cin >> a >> b >> c;

[Code] ....

View 5 Replies View Related

C :: Fgets Does Not Read The Complete Tab Separated Line

Sep 16, 2013

I have prepared a file through the use of following code

Code:
fprintf(file2, "%i %i %i %i %i %i
",
msg_id,
msg_size,
msg_period,
msg_deadline,
msg_producer,
msg_comsumer
);

As one can see, this file has tab separated integer entries. The file is written correctly, let us call this file "msg.txt".

I face the problem when I read this file, using fgets as follows:

Code:
char singleMessage[100];
while( fgets(singleMessage, sizeof(singleMessage), file ) )
{
puts(singleMessage);
sscanf(singleMessage, "%i %i %i %i %i %i
",
&first, &second, &third, &fourth, &fifth, &sixth);
fprintf(stderr, "first: %d, second: %d, third: %d, fourth: %d, fifth: %d, sixth: %d
",
first, second, third, fourth, fifth, sixth);
}

but fgets only retrieves until the first, i.e, if the first line in the file reads:

788004425

fgets returns only 78.

Does it have to do with how the file was written in the first place.

View 1 Replies View Related

C++ :: Are Variables Being Defined As Parameters Separated By Comma

Jan 18, 2013

TinyGPS::TinyGPS()
: _time(GPS_INVALID_TIME)
, _date(GPS_INVALID_DATE)
, _latitude(GPS_INVALID_ANGLE)

[code]....

I am wondering about the constructor. I see there appears to be nothing inside of TinyGPS::TinyGPS() as far as parameters go and that that declaration is followed by a ":". First I'm wondering as to the meaning of the colon. As well with the variables defined after the ":" I see some "(0)" and I am wondering as well to the exact meaning of the "(0)". Are those variables being defined as parameters separated by ","?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved