|
The extra 16 characters are coming from the \r's that are attached to the \n's. If you want, you can just ignore the check for the size and use the buffer as is. There is a way to tell the f-functions to read \r's as well, but I can't remember how off the top of my head.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
int i = 0;
data[i] = strtok( buffer, " " );
printf("data[%d] = %s\n", i, data[i]);
do
{
i++;
data[i] = strtok( NULL, " " );
printf("data[%d] = %s\n", i, data[i]);
}while(data[i] && i<200);
how does one get strtok() to ignore a newline character?
Kitty5
-- modified at 17:59 Thursday 29th June, 2006
|
|
|
|
|
One way is to do a strtok on the '\n' character itself, which will give you a set of 0xXX strings.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Here's how I would do it:
-------------------------
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
int main(int argc, char* argv[])
{
using namespace std;
// Open the file for reading.
ifstream ifs("C:\\a.txt");
if (!ifs)
{
cerr << "Unable to open file" << endl;
return 1;
}
// Read in the contents of the file.
typedef string type_t; // You can change the type of the data here.
typedef vector<type_t> container_t; // The collection we use to store the data we read.
container_t FileContents;
copy(
istream_iterator<type_t>(ifs), istream_iterator<type_t>(),
back_inserter(FileContents)
);
// Write the contents of the container to the console.
copy(
FileContents.begin(), FileContents.end(),
ostream_iterator<type_t>(cout, "\n")
);
return 0;
}
-------------------------
Changing a single line as follows reads and stores the data as ints instead or strings:
typedef int type_t; // You can change the type of the data here.
Steve
|
|
|
|
|
A static variable is local to particular function. However, it is only initialised once (on the first call to function).
Also the value of the variable on leaving the function remains intact. On the next call to the function the the static variable has the same value as on leaving.
This is the definition I got on one of the websites
Static sounds like a CONSTANT. Replacing static with a constant sounds like the same thing.
Does that make sense to you guys????
-- modified at 14:41 Thursday 29th June, 2006
|
|
|
|
|
Jay03 wrote: Does that make sense to you guys????
not at all !!
void inc() {
static iCpt = 0;
iCpt++;
printf("%d\n", iCpt);
}
void main(void) {
for (int i = 0; i < 10; i++) {
inc();
}
}
this code actually prints :
1
2
3
4
...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Jay03 wrote: Static sounds like a CONSTANT.
No. They are different. I think you misunderstood "it is only initialised once". Look at this example:
YourFunction()
{
static int st = 0;
st++;
}
You sound pretty new to C/C++. Get a book and study it more systematically.
Best,
Jun
|
|
|
|
|
Jay03 wrote: Static sounds like a CONSTANT.
Not even close. When a variable has static duration, it is allocated when the program begins and deallocated when the program ends. A const variable specifies that the variable is not modifiable.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I am using visual c++ 6.0;
I want to print numbers with thousand separator, what format to use.
I have float variables that i want to print like these:
252,000.00
150,250.25
What to do ?
|
|
|
|
|
If this is with a Win32 application, use GetNumberFormat() . Otherwise, you'll need to roll your owwn.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Hi all,
I downloaded EasyInstaller2 and NSIS, too,
but they are too difficult to me.
Could anybody explain to me how to use
one of the two to create an installer for
my Visual C++/MFC .NET project ?
Thanx in advance,
Desmo16.
|
|
|
|
|
How about XCOPY ?; After all, .Net was touting "the end of DLL Hell" and "XCOPY deployment"...
Seriously, I am not familiar with either of those installers - I use Wise.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Hi,I want to write COM dll..for serial port communication of an instrument,i want write code to open,close,read and write data to port in the DLL.I want valueable suggestions..guidence..to start..
I request any existing articles on this..so that they can be useful to me..
thanks in before
James
-- modified at 13:01 Thursday 29th June, 2006
|
|
|
|
|
Start here.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
thanks for the response..David is there any sample application..for the given article
|
|
|
|
|
RockyJames wrote: ...is there any sample application..for the given article
Did you read it? Near the bottom it states:
"There is no download because copy-and-paste from this page should suffice."
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
yeah i have..read..thanks for the article..Can i expect any more suggestions like how to start..i want the basic push up..then later on i hope i can handle.it..
|
|
|
|
|
here
That article is more about creating pluggable COM components, but the source code has a serial port component that will fill your needs.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
i am new to COM,i want to develop a DLL in COM for serial port communication,the component side, i want to write code,for opening the COM port,closing,sending and receiving the Data,from the client side i want to use this DLL./and just call the respective function of the DLL..can u please suggest me..how to use your serial communication interface..
thanks in before..
james
|
|
|
|
|
That is what those components do. There are 3 COM components and 1 client app in the demo code for that article. The app itself is very straight-forward. Instead of looking for the components of a specified category, just import the serial port one into your project and initialize it the same way it is done in the application.
Have you written serial port code before? If not, you may want to start by writing a class to communicate with the serial port prior to jumping into COM.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
can i use u r serial communication class directly ,instead of developing new one..?
-- modified at 19:21 Thursday 29th June, 2006
|
|
|
|
|
Serial communication in Windows is handled just like a file. You use OpenFile/CreateFile to open the port, and ReadFile/WriteFile to read from and write to it. The classes people develop just wrap these operations into easy to use methods.
So, yes, you can easily just use the Win32 API directly if you would like.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
yeah i am planing to use OpenFile/CreateFile,ReadFile,WriteFile and other API functions,do we need to write two threads,for reading and writing and how do we spool the data.I want write everthing in a DLL and use this DLL,in a client application,by calling respective functions,i want to open com port,send,and read from it....
Thanks in Before
james
|
|
|
|
|
need to add some images thumbnail to CImageList
|
|
|
|