I am reading in a comma delimited text file, with a document #,revision
letter on each line.
example:
123,A
456,B
There are 19000 lines to this master document file. I will also be
reading in a file that has about 200 lines that has the same structure
as the first file. I need to compare File A and B and produce File C.
The 123 document data is the same in A and B file, I am looking if the
REVISION has been updated in the master document file A. If there is an
update of the REVISION then I want to copy that line of File A,
overwrite it in File B, and create file C with these lines that have
been found as updates.
The final program needs to take the data in file C and create a MS Word
Document, email it, and print it. This program will run once a day
after file A gets updated from a database query and act as an
automated document ordering system.
I am not the master of C by any means but I am trying my best to learn
more. I am more use to scripting from the 80's.
I am trying to use Visual C++ 2005 express
I am getting stuck with the following code because I get the an error
during compile when I try putting pointers into a new array that I have
commented out.
Here is the code that I am having problems with. Maybe I am going about
it the wrong way.
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define MOVEX_QUERY "C:\\DWG_DATA\\ DOCUMENTS_movex .dat"
int main(){
char * document;
char * edition;
char * str1;
char * next_token1;
int i=0;
string tmp;
using std::ifstream;
using std::cout;
ifstream inf(MOVEX_QUERY );
if (inf)
{
char namn[20000][30];
char doc[20000][30];
char edi[20000][30];
while ((inf.getline(n amn[i], 30)) != NULL)++i;
for (int i = 0; i < 5; ++i){
str1 = namn[i];
document = strtok_s( str1, " ,\t\n", &next_token1 );
edition = strtok_s( NULL, " ,\t\n", &next_token1 );
// doc[i] = document; // does'nt work
// edi[i] = edition; // does'nt work
if(document == edition) printf( "%s\n", document ); // does'nt work
// printf( "%s\n", document );
// printf( "%s\n", edition );
// cout << i <<'\n';
}
}
else
{
cout << "Could not open file\n";
return 1;
}
cout << "PROCESSING COMPLETE\n";
return 0;
}
This is only some test code trying to read in and do comparisons on
variables. I was thinking that I could read in all of file A and B,
then loop thru A for each record of B while building C.
Any help Please! 8 7734
* electrixnow: I am reading in a comma delimited text file, with a document #,revision letter on each line. example:
123,A 456,B
There are 19000 lines to this master document file. I will also be reading in a file that has about 200 lines that has the same structure as the first file. I need to compare File A and B and produce File C. The 123 document data is the same in A and B file, I am looking if the REVISION has been updated in the master document file A. If there is an update of the REVISION then I want to copy that line of File A, overwrite it in File B, and create file C with these lines that have been found as updates.
std::map<int, char> bData = dataFrom( pathToB );
std::ifstream a( pathToA );
std::ofstream c( pathToC );
while( !!a )
{
-- read one line from a
-- split the line into document # and revision char
-- check against bData
-- if different revision char:
-- update bData
-- write line to c
}
assert( a.eof() );
save( bData, pathToB );
Any help Please!
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
you cannot assign char* strings in c++. use
strcpy(doc[i],document);
instead.
if you use strcpy() you also have include <cstring>.
Sorry but I am a newbie and I searched for usage on std::map and found
nothing.
Can you give me an exact example of
std::map<int, char> bData = dataFrom( pathToB ); // open file for
read & write
std::ifstream a( pathToA ); // open file for read
std::ofstream c( pathToC ); // open file for write
while( !!a ) // don't understand the double !! // is it looking for
NULL or EOF
{
-- read one line from a // I can use inf.getline
-- split the line into document # and revision char // should I
use strtok_s
-- check against bData // do I check using strings or pointers,
do I cast? how
-- if different revision char:
-- update bData
-- write line to c
}
assert( a.eof() ); // are you checking for eof again
save( bData, pathToB ); // could'nt find save usage in help
Sorry I am not an expert, but I am new and this task seems simple but
has been
frustraiting. I was hung up on cannot convert from 'char *' to 'char'
I understand the flow you created and it's on the money. I wish I had
some good examples to study. I have been looking all over and have not
found any good sites with lots of simple VC++ examples.
Please help.
if I use strcpy(doc[i],document); I get a message from compile that
says it's unsafe and to use strcpy_s instead. when I run the program I
get a stack overflow with strcpy
are you using VS C++
Sorry but I am a newbie and I searched for usage on std::map and found
nothing. Can you give me an exact example of:
std::map<int, char> bData = dataFrom( pathToB ); // open file r/w
std::ifstream a( pathToA ); // open file for read
std::ofstream c( pathToC ); // open file for write
while( !!a ) // why 2 ! // looking for NULL or EOF
{
-- read one line from a // I can use inf.getline
-- split the line into doc # and rev char // use strtok_s ?
-- check against bData // use string or pointer ?
-- if different revision char:
-- update bData
-- write line to c
}
assert( a.eof() ); // are you checking for eof again
save( bData, pathToB ); // could'nt find save usage in help
Sorry I am not an expert, but I am new and this task seems simple but
has been
frustraiting. I was hung up on cannot convert from 'char *' to 'char'
I understand the flow you created and it's on the money. I wish I had
some good examples to study. I have been looking all over and have not
found any good sites with lots of simple VC++ examples.
Please help.
electrixnow schrieb: I am not the master of C by any means but I am trying my best to learn more. I am more use to scripting from the 80's.
I am trying to use Visual C++ 2005 express
I am getting stuck with the following code because I get the an error during compile when I try putting pointers into a new array that I have commented out.
Your are mixing C and C++ here.
Don't use pointers and arrays, if you don't need to. Use strings and
vectors, they are much easier to use once you know them.
You can't assign and compare arrays of chars:
char text[100] = "Some text";
char text2[100] = "some other text";
if (text == text2) { ... } // does not work
text = text2; // does not work
Use this:
string text = "text";
string text2 = "other";
#include <stdio.h> #include <stdlib.h>
This two are C headers. The C++ equvalents are <cstdio> and <cstdlib>,
but you don't need them here.
using namespace std;
#define MOVEX_QUERY "C:\\DWG_DATA\\ DOCUMENTS_movex .dat"
const string movex_query = "C:\\DWG_DATA\\ DOCUMENTS_movex .dat";
int main(){ char * document; char * edition; char * str1; char * next_token1;
replace char* with string.
int i=0; string tmp;
using std::ifstream; using std::cout;
ifstream inf(MOVEX_QUERY );
ifstream inf(movex_query .text()); if (inf) { char namn[20000][30]; char doc[20000][30]; char edi[20000][30];
vector<string> namn;
and so on...
Read about vector and string. string has some usefull member functions.
Thomas
In article <11************ *********@o13g2 000cwo.googlegr oups.com>,
"electrixno w" <info...@charte r.net> wrote: I am reading in a comma delimited text file, with a document #,revision letter on each line. example:
123,A 456,B
There are 19000 lines to this master document file. I will also be reading in a file that has about 200 lines that has the same structure as the first file. I need to compare File A and B and produce File C. The 123 document data is the same in A and B file, I am looking if the REVISION has been updated in the master document file A. If there is an update of the REVISION then I want to copy that line of File A, overwrite it in File B, and create file C with these lines that have been found as updates.
Do the lines have to maintain their order?
The final program needs to take the data in file C and create a MS Word Document, email it, and print it. This program will run once a day after file A gets updated from a database query and act as an automated document ordering system.
I am not the master of C by any means but I am trying my best to learn more. I am more use to scripting from the 80's.
I am trying to use Visual C++ 2005 express
I am getting stuck with the following code because I get the an error during compile when I try putting pointers into a new array that I have commented out.
Here is the code that I am having problems with. Maybe I am going about it the wrong way.
Maybe this will help:
ifstream afile( "document_n ame" );
string str;
while ( getline( afile, str ) ) {
try {
// lexical_cast can be found in the boost library
string::size_ty pe comma = str.find( ',' );
int doc_num = lexical_cast<in t>( str.substr( 0, comma ) );
char rev = str.substr( comma + 1 ).at( 0 );
// at this point the line has been parsed.
// do what you want to it.
}
catch (...) {
cerr << "bad data found in document";
}
}
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim Johansson |
last post by:
I'm new to C++, and tried to start making a script that will shuffle an
array. Can someone please tell me what's wrong?
#include <iostream.h>
#include <string.h>
int main () {
srand(time(0));
int array_length;
int count;
|
by: Peter |
last post by:
Hi,
So many times, I have seen compile warning: "you used a char* without
initilize it", probably on the code like this:
------------
char* ptr;
func(..., ptr);
----------
|
by: Anton Pervukhin |
last post by:
Hello!
Imagine the situation you have a class that interprets the command line
of the program you are executing. This class is written by third party
and has a main function parse with arguments the same as main:
ClassA::parse(char **argv, int argc)
While trying to write test cases for this function I came across the
warnings appeared when I tried to initialize 'char** argv' straightly
|
by: Radde |
last post by:
Hi,
class String
{
public:
String(char* str);
void operator char*();
|
by: Peter Nilsson |
last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think
about what the conversion of a char to unsigned char would mean, and whether
it was sensible to actually do so. And pete has raised a doubt in my mind
on the same issue.
Either through ignorance or incompetence, I've been unable to resolve some
issues.
6.4.4.4p6 states...
| |
by: Kevin Frey |
last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the
new C++/CLI syntax rather than /clr:oldSyntax.
Much of our managed code is concerned with interfacing to native C++ code
(ie. wrappers etc). In Managed C++ there was an automatic conversion between
const char* and String^. This was useful to us for two reasons:
1. We declared our string constants as eg. const char* const c_My_Constant =
"blah", and these...
|
by: arnuld |
last post by:
what is the difference between these 2:
char name = "hackers";
char* name = "hackers";
|
by: utab |
last post by:
Dear all,
I was trying to write a more complex program, and while searching for
sth in my reference C++ primer, by Lippman. I had a question in the
mind, see the code below
#include <string>
#include <iostream>
#include <cstring>
int main(){
|
by: Angus |
last post by:
I am working with a C API which often requires a char* or char buffer. If a
C function returns a char* I can't use string? Or can I? I realise I can
pass a char* using c_str() but what about receiving a char buffer into a
string?
Reason I ask is otherwise I have to guess at what size buffer to create?
And then copy buffer to a string. Doesn't seem ideal.
|
by: Eric |
last post by:
I am working on a large, old code base and attempting to move it to
GCC 4.2. Throughout the code, there is stuff like:
char *aVar = "aString";
or
void aFunc( char *aVar) { ... }
aFunc( "aString" );
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |