473,382 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Read strings from a one dimensional buffer...

Hi Friends,

I am trying to create a log of some of the outputs. For this I am using
doing the following things...

char * buff = malloc(SIZE);

buff[0] = id_number
len = strlen(data);
memcpy(&buff[1], data, len);

and so on.....

So, in buffer, my data will be ...

1aaaaaaaaaaaa2bbbbbbbbbbbbbbbb3ccccccccccc....

For some reasons, I can not use the Files. So I have to stick to
malloced buffer.

Now, I want to read this data. For me, "1aaaaaaaaaaaa" is one set of
data wherein '1' is the id_number and "aaaaaaaaaaaa" is actual data.
Pls note that length of the actual data is unknown. So practically
there are no delimiters. I was counting on the id_number as the
delimiter. But when I use sscanf, it reads 1a instead of 1.

How can I read this ? Is there any better method?

Thanks in advance,
ImMa...

Nov 15 '05 #1
5 4044

imma wrote:
Hi Friends,

I am trying to create a log of some of the outputs. For this I am using
doing the following things...

char * buff = malloc(SIZE);

buff[0] = id_number
len = strlen(data);
memcpy(&buff[1], data, len);

and so on.....

So, in buffer, my data will be ...

1aaaaaaaaaaaa2bbbbbbbbbbbbbbbb3ccccccccccc....

For some reasons, I can not use the Files. So I have to stick to
malloced buffer.

Now, I want to read this data. For me, "1aaaaaaaaaaaa" is one set of
data wherein '1' is the id_number and "aaaaaaaaaaaa" is actual data.
Pls note that length of the actual data is unknown. So practically
there are no delimiters. I was counting on the id_number as the
delimiter. But when I use sscanf, it reads 1a instead of 1.

How can I read this ? Is there any better method?

Thanks in advance,
ImMa...


Well, if there can be digits in the data or if you want more
than CHAR_MAX elements you are out of luck with the
format described.

Otherwise, you could use a combination of
strtol(buf, &endptr, 10);
and
strcspn(endptr, "0123456789");
to sort out your string.

-David

Nov 15 '05 #2
imma wrote:

For some reasons, I can not use the Files. So I have to stick to
malloced buffer.


What do you mean by this?
Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Nov 15 '05 #3
I am going to use this code in real time environment. so i guess file
operation, malloc of buffers wont be feasible. Hence I will allocate
big chunk of memory during initialisation and use it for logging..

Nov 15 '05 #4
"imma" <ma******@gmail.com> writes:
I am going to use this code in real time environment. so i guess file
operation, malloc of buffers wont be feasible. Hence I will allocate
big chunk of memory during initialisation and use it for logging..


What code?

Don't assume we can see the article to which you're replying. You
need to provide some context so each followup can be read on its own.
See most of the followups posted to this newsgroup for examples.

Google makes this gratuitously difficult to do properly, but there
is a workaround:

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

And please complain to Google about their broken interface.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #5

imma <ma******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi Friends,

I am trying to create a log of some of the outputs. For this I am using
doing the following things...

char * buff = malloc(SIZE);

buff[0] = id_number
len = strlen(data);
memcpy(&buff[1], data, len);

and so on.....

So, in buffer, my data will be ...

1aaaaaaaaaaaa2bbbbbbbbbbbbbbbb3ccccccccccc....

For some reasons, I can not use the Files. So I have to stick to
malloced buffer.

Now, I want to read this data. For me, "1aaaaaaaaaaaa" is one set of
data wherein '1' is the id_number and "aaaaaaaaaaaa" is actual data.
Pls note that length of the actual data is unknown. ^^^^^^^^^
The strlen function takes care about that. The argument in strlen are passes
a pointer.

So practically
there are no delimiters. I was counting on the id_number as the
delimiter. But when I use sscanf, it reads 1a instead of 1.

How can I read this ? Is there any better method?

Looking at the section 7.21.5 of the 2005 std may help.


Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
1
by: Reginald Carlier | last post by:
Hi, I'm programming a game and one of the variables is a two dimensional array in wich I store the names of the players. So far so good; with cin.get I ask the names of the players and...
9
by: Rafi Kfir | last post by:
Hi, This may look as a smiple task to most of you, but to me (a beginner with C), it drives me crazy. All I want is that one function passes a two dimensional array of strings to another...
9
by: Carramba | last post by:
#include <stdio.h> int main( void ){ char cQuit = 'a'; char cKommando , artistNamn , skivansNamn , cChar; int cK ; FILE *pekaFile; printf( "l - for read file\n"); printf( "s - for writte...
6
by: Giff | last post by:
Hi I have this problem that I can't solve, I know it shouldn't be hard but I'm not a good coder and I'm going crazy tonight... I have a txt file that goes like this: string1 string2...
15
by: I. Myself | last post by:
This is about reading the .ini files which are used in several of our projects. Currently, the actual read of each line of the file is with this statement: fscanf(file, "%s %s", name, value);...
4
by: nass | last post by:
hello everyone, i have a bit of problem reading char * strings from a buffer (a shared memory, pointed to by 'file_memory'). basically i have a structure in memory 'ShMem' that can be accessed by...
14
by: WStoreyII | last post by:
the following code is supposed to read a whole line upto a new line char from a file. however it does not work. it is producing weird results. please help. I had error checking in there for...
6
by: ma740988 | last post by:
I'm perusing a question and curiosity got the best of me in part because I cant solve the problem Consider: typedef unsigned int word_type ; class foo { public: void set_mx_digits_1 (...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.