oh man, that was it .. i got the point narue and i fixed the code once and for all. for safety reason i've still kept the memset. That was a logical mistake and a bad one, need to look out for such things in future.
thanks a ton
chandra
oh man, that was it .. i got the point narue and i fixed the code once and for all. for safety reason i've still kept the memset. That was a logical mistake and a bad one, need to look out for such things in future.
thanks a ton
chandra
Since i was doing a (length-1) in the loop that was not the problem. i had forgotten to do a memset after allocating memory, added this line of code
char* px = new char[length];
memset(px,'\0',length); // added this
after the this it seems to be working fine. is this a mandatory step in all situations?
thanks a lot
chandra
cool...
when i do a cout of this string i get something like this
<?xml version="1.0" encoding="UTF-16"?>
<Company>
<Division>
<Employee>
</Employee>
</Division>
</Company>/
or any other char appended to the last tag
i have tried using this code
const char* ps = reinterpret_cast<const char*>(requestBody.Data());
String inpMessage(ps);
size_t Offset = inpMessage.FindFirst(TEXT("</Company>"));
const char* pm = "</Company>";
char* pn = strstr(ps,pm);
size_t end = 0;
while ( *pn != '>')
{
end++;
++pn;
}
end = end+2;
size_t length = Offset + end;
char* px = new char[length];
//memcpy(px,ps,length);
int i;
for(i=0;i<(length-1);i++)
{
px[i] = *ps;
*ps++;
cout << px[i];
}
i++;
px[i] = '\0';
cout << px[i] << endl; //till here no extra chars
cout << px << endl; //here it shows the appended char
RWTString inMessage(px);
delete [] px;
here requestBody.Data() is the input. it returns a void* . i used the position of the last tag to get the length of the string and then tried copying the data but still sometimes after the closing > of the last tag i'm getting some char appended to string. what is interesting is that when i did a cout of each char inside the while loop it doesnt show that there are any extra characters but when i do a cout of the entire char* in one shot it shows that there's an extra character.
because of which the XML does not get parsed at all. String class is our own …
hi,
I have a XML in a String coming from an external input. The problem is that this string is getting some junk characters appended to in the last. I need to find the lenght of the string only till the correct part. once i get this lenght i can assign a char array for this lenght and put my string into this array and pass it for processiing. basically i have to get rid of the junk. any ideas?
example string
"<?xml version="1.0" encoding="UTF-16"?>
<Company>
<Division>
<Employee>
</Employee>
</Division>
</Company>
"
I dont think so. just put the loop and print each element. however you can format the output in any way, everything in 1 line, separate lines, tabs etc.
cout << data[index]
Hi Guys,
In my project the user will enter the name of the organization and it's floor map has to be displayed. the maps have to be made by us and need not be complicated at all. what i want to know is that what technologies can i use to do this? the backend has to be in either c++ or java with an oracle DB. should i use CAD? as i've never worked on CAD before i have no clue how it'll get integrated with C++ and if it can be useful for me or not or can i use C++ to make the maps? they need not be 3d maps, it can b 2d but need to be very presentable/colorful/easy to read etc
any directions will be very helpful.
thanks
chandra
use the search text box on the top right hand corner of your screen. search in this forum for 'validating input' or something like that. you will get some good ideas and approach.
yeah.. that should be it .. since the int's are not initialised either ... i just copied the name from the code and created the file.. OP please check that..
dude i compiled and executed ur code... output was just as expected ....
is this line still there?
DWORD d = 0;
you have c1,c2,c3 declared in global as int then inside the fn as char and then again as int... what r u trying to do? you declare them as char then you pass them to cResist which takes int, so it has the ASCII values and then you pass them to another fn and use them in a switch ... i think the first step should be to understand what kind of var you need and declare them properly..
have you written some code?
n i didnt check.. the do-while loop is not used like this .. please check the correct way of using it ...
dont put everything in main. write separate functions to perform different operations. that way your code will b more modular and easy to maitain and make changes.
you mean to say that when the user says 'no' to this "cout << endl << "Another order? (Y/N)";" you want to add up those numbers for the entire user order..rt?
for the correct way of doing this lets first put everything inside the while loop first.
while ( (ans != 'n') && (ans != 'N')
put everything inside this loop.. you dont need to ask this in the end... just initialise 'ans' with a ''. at the end of the loop, ask the user if he wants to enter more orders.. if yes then it'll loop or else you will come out of the loop and sum the numbers. use member variables or local variables(but declared outside the while loop) for storing the cost etc..
ok. so u'll enter the examcode in say [0][0] and corresponding marks in [0][1] or something like that ...? and what do you mean by "fill the space with examcode automatically" ?
let me first check if i got the qs correctly.. you get a string of characters as i/p. it has chars from a to h and some chars might have more than one appearance in it .. so as of now u have been able to count the number of times each char is present in the i/p..rt? n u have to print them as many times... so for each char you send the entire i/p to the count fns n they tell you how many times its present... is that rt?
question is not very clear ... where is the examcode? where r u putting it?
once you return the number, just put a for loop with that number and cout the alphabet that many times...
after you do the getname, do a getpopulation, divide the return value by 1000 and print it ...
what is coclass?
one correction ..
this.m[x] = c;
should be
this->m[x] = c;
Collect add;
add.director=director+c.director; \\string
add.title=title+c.title; \\string
add.genre=genre+c.genre; \\string
add.length=length+c.length; \\int
add.rating=rating+c.rating; \\string
add.release=release+c.release; \\string
collect class doesnt seem to have these members at all(director,title etc..)
what you should, if you have no option but to use the operator overloading
void Collect::operator+(const Movie& c){
this.m[x] = c;
;}
i dont think you need to return anything either in this case, simply add the movie to the array ... you will have to keep a tab of the number of elems in the array so that you add it at the right position..
To me the usage of operator overloading to do this doesnt seem good.. you have a collect class and that has an array of movie class. simply write an addMovie function in collect class, pass on the movie object to it and insert it in the array. neat and much easy to understand. have you been speicifcally asked to do it using operator overloading?
deleted what? ... you dont want to sol any more?
method of learning i use is to take up a book and start with the basics.. try simple programs for the each topics and then move ahead.. dont rush, dont expect to learn everything in a day and dont try and jump to complex topics without learing the basics .. you can forget about the XOR and array for now and implement the swap method suggested by joeprogrammer.. also writing down the algorithm before starting really helps..
when you add the next movie to the same collect object doesnt it override the existing values? how are you storing it? if possible plz post a bigger fragment of the code, its difficult to understand like this ...
i think it would b better if you take them in an array ...
for swap i would suggest you use the XOR (^) operator to do it without a temp..
dont seem to get it ... you have a class called collect.. the attributes if that class are initialized from some attributes of the movie class, rt? where is the array? can you put the code where you are using this operator?
ok..then while fetching you need another loop... to take the 3rd subscript .. it should b something like
list[j][k]
what i dont understand is, y do you need a 3d array to hold only the last names of the passengers? just a 2d array shd work well.. and this will not create an array with 15 rows and 6 columns.. it will be 15 2d arrays with each 2d array is actually a collection of 6 1D arrays capable of holding 20 chars..
i wish i could.. but i'm kind of busy right now.. to help you move ahead i can tell you what to do..
take STL documentation and read about maps , they are containers that can store key/value pairs.
then read the contents of the file using
inFile >> elem; this will read till next white space, since i dont know how ur file is arranged, i think this will work..
once you have the id/radius pair, insert it in the map. then you can use the 'find' method on the map to get the corresponding radius..
and i realised that you will have to do this everytime the user takes option 2, coz the user might have added more entries to the file in between...
and it just struck me that since this step is done everytime you might as well not do it all and instead keep comparing the values as and when you read from the file without inserting in the map ... sorry if i confused you :)
i would suggest you load the contents of the file in a map either in the beginning or when the user chooses option 2 and then when the user enters the Id of the circle, fetch the corresponding circle details and print it ..
1>structure is a user defined data type, so once the user defines it he can use it just like any other data type, like in your struct you have 2 variables of type char and int, similarly you can add another variable of some struct data type. suppose there was another structure called employee, then you could say
struct employee
{
int empId;
...........
}
then
struct data
{
employee e; //structure within structure
int age;
...
}
2> i can tell u, but it's pointless...
well i'm assuming that you have done the rest of the code correctly..... and if you can tell me the error it's throwing then i might help.. but as far as ur initial qs is concerned the proposed sol will work..
Inside the Inner Loop
for (i=0; i < 3; i++){
for (j = 0; j < 3; j++)
{
inFile >> matrix[i][j];
printf("\n%f\t%f\t%f", matrix[i][j]);
}
}
like this..
it doesn't say what are the number of rows or columns in the matrix...
sorry for the repetition, i guess i didnt refresh for long :) ...
as user for i/p i meant 'ask' user for i/p
btw if matrix size is undefined at compile time then simple array will not work as you wont know the dimensions..
declare a 2 dim array.
inside the inner loop, as user for i/p and keep storing in each element of the array.
--post the code inside code tags
actually your first qs is more interesting .. n something i'm trying to understand too... how to decide whether to keep it as a pointer or and object. i'll share whatever is my understanding..
what we are trying to do here is create a 'has-a' relationship.. a composition.. so basically your MyFrame class which derives from Window 'has-a' Library. if you keep it as a pointer then in future if your MyFrame class doesn't need a libarary any more you can simply assign the pointer to NULL. However adding a pointer means you need to worry about memory management. If you are sure that MyFrame will always have a library, you can keep it as an object, and MyFrame will take care of its creation and deletion. If the library Object is too large then it will add to size of MyFrame object.
will have to find the best possible solution for your case. My understanding at this point is basic, but it might help you to start off...
dude i just executed your code .. n it was as smooth as fine scotch on rocks ... no segmentation faults... wish i could help...
printf("%d\t", matrix[j]); shd be inside the inner loop ...
if you assign memory on the heap in ur code then you have to release that too.. in the first case in your destructor you should delete the pointer to release the memory.
in the second case the creation and deletion of object will be taken care of by the class,you dont have to worry about calling the library class destructor in myframe, that will get called automatically..
without trying to understand the logic i can tell u a few things ..
> change 'main' to 'int main'
>
change
nWords = numWordsInFile( textFile, nWords);
to
only
numWordsInFile( textFile, nWords);
&
int numWordsInFile( ifstream &in, int &nWords)
to
void numWordsInFile( ifstream &in, int &nWords);
as here you'r passing nWords by reference so you dont need to return anything from this function, nWords will automatically have the calculated value as its a reference.
similary for the other function also.
3> no need to create local variables in these functions, manipulate the reference directly.
then i'd suggest you dont waste your time here.. nobody will help you unless you show us what u've tried ... there are a lot of c++ tutorials available online ...
if you post the code you wrote and tell us at which point you're getting stuck then we can give you some good advice...
i'm not really sure how to do that.. will try and find out ... thanks a lot ...