|
Please don't repost the same question. You have already asked this in the Q&A section.
|
|
|
|
|
Is it possible in C++ to declare a pointer as long?( like long int).
I'm reading some string from a XML file and assigning it to a <code>const char*</code> variable.
But the application crashes, when string is huge. Is there any maximum limit for char * variable?
How to avoid the crash,when the string is huge?
|
|
|
|
|
pix_programmer wrote: Is it possible in C++ to declare a pointer as long?( like long int). On most platforms, both are 32-bit so there would be no difference.
pix_programmer wrote: Is there any maximum limit for char * variable? A pointer just points to something.
pix_programmer wrote: How to avoid the crash,when the string is huge? Showing the relevant code, for starters.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
A pointer is a pointer is a pointer; it is a fixed size and has nothing to do with the length of the item(s) that it is pointing to. You need to use your debugger to investigate why your program is crashing.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
pix_programmer wrote: I'm reading some string from a XML file and assigning it to a <code>const char*</code> variable.
That doesn't make sense. A pointer can only be sensibly initialized within the program, at runtime, because only then does the computer know where in memeory every object lies. Therefore it doesn't make sense to either store or restore a pointer to/from a file!
What you need to do instead is:
1. read that string from your file
2. Allocate a char array on the heap that is big enough to contain that string (including the terminating NULL character!)
3. Assign that array to your pointer
4. Store the string in that char array.
Of course, if you use std::string , that would save you some of that efort.
|
|
|
|
|
Stefan_Lang wrote: Therefore it doesn't make sense to either store or restore a pointer to/from a file! I think the "it" the OP was referring to was the string, not the file.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I'm not so sure - he (or she) asked about using a bigger pointer type after all.
In any case, I've found that it's often better to take a question literally - if it isn't meant that way, it helps the author to improve on it and provide a better description of the actual problem.
|
|
|
|
|
Application crash has nothing to do with the size of the pointer. You should show us the relevant code to get better help.
Veni, vidi, vici.
|
|
|
|
|
A pointer is just a pointer, just pointing to something. I think your application is crashing with some other reason. just debug the code and ensure what is the problem.. if you are using visual c++ just using LPCTSTR variable for storing string data read from xml.
|
|
|
|
|
Hello there,
In computer science, a pointer is a programming language data type whose value is directly linked to another - by means of pointing to the value that is stored elsewhere in the computer memory using its address.
The basic syntax is define a pointer is as follows:
int *ptr
Now, because a pointer points to a memory location - I don't believe that it can be define as long.
With Kind Regards,
Live Support Software for Business
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:43am.
|
|
|
|
|
i need to make program that i give some system command like ls,date et cetera.and to check if thre is path that include this command(file).i have variable commandandparameters that start to change in the last loop while and i dont know why.
i put puts(commandandparameters); to show that the output is not good if you want to run it.
#include <stdio.h><br />
#include <string.h><br />
#include <stdlib.h><br />
void main()<br />
{<br />
char *arr[5];
char command[10];<br />
int i,j;<br />
char *path=NULL,*tempath,*finalpath,*commandandparameters;<br />
do<br />
{<br />
i=0;<br />
printf("enter new command:");<br />
gets(command);<br />
arr[i]=strtok(command," ");<br />
while(arr[i]!=NULL)
{<br />
i++;<br />
arr[i]=strtok(NULL," ");<br />
}<br />
strcpy(commandandparameters,arr[0]);
for(j=1;j<i;j++)
{<br />
strcat(commandandparameters," ");<br />
strcat(commandandparameters,arr[j]);<br />
}<br />
path = getenv("PATH");<br />
tempath = strtok(path,":");<br />
while (tempath != NULL)<br />
{<br />
strcpy(finalpath,tempath);
puts(commandandparameters);<br />
strcat(finalpath,"/");
execl(finalpath,commandandparameters,NULL);<br />
tempath = strtok(NULL, ":");
}<br />
}while(command!="leave");<br />
}
|
|
|
|
|
Some code is missing in your post.
(And please, elaborate a bit).
Veni, vidi, vici.
|
|
|
|
|
Your question is not clear, and your code snippet is incomplete. However I did notice the line:
strcpy(commandandparameters,arr[0]);
This is likely to fail since you have not initialised commandandparameters to point to anything.
Note, please use <pre> tags around your code (as I have done above), rather than <code> tags.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
char *arr[5]; char command[10];
int i,j;
char *path=NULL,*tempath,*finalpath,*commandandparameters;
do
{
i=0;
printf("enter new command:");
gets(command);
arr[i]=strtok(command," ");
while(arr[i]!=NULL) {
i++;
arr[i]=strtok(NULL," ");
}
strcpy(commandandparameters,arr[0]); for(j=1;j<i;j++) {
strcat(commandandparameters," ");
strcat(commandandparameters,arr[j]);
}
path = getenv("PATH");
tempath = strtok(path,":");
while (tempath != NULL)
{
strcpy(finalpath,tempath); puts(commandandparameters);
strcat(finalpath,"/"); execl(finalpath,commandandparameters,NULL);
tempath = strtok(NULL, ":"); }
}while(command!="leave");
}
|
|
|
|
|
Very nice, but you still have not explained your problem clearly. What results are you seeing in your program and what results do you expect to see?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
When posting question, first you should ensure that my problem is clearly mentioned. because we cannot read your mind or monitor. you posted your code section , that is good. but exactly what is your problem?
|
|
|
|
|
How to merge two arrays?
Consider the following two arrays:
int a[3] = {2,3,5};
int b[3] = {4,6,8};
These two arrays has to be merged and stored in a third array c.
My expected result would be :
c[6] = {2,3,5,4,6,8};
How to do this?
|
|
|
|
|
OK, I had to delete my first answer, because it was a C# solution. Sorry. Now my brain is switsched in C-mode
You can use memcpy. But allways be aware of the size of the target array! It has to be large enough to take all of the elements.
int a[] = { 2, 4, 6};
int b[] = { 3, 5, 7};
int c[6];
memcpy(c, a, sizeof(a));
memcpy(c + 3, b, sizeof(b));
Hope it helps.
|
|
|
|
|
pix_programmer wrote: How to do this? Coding!
Another option would be using std::vector , and using the insert[^] method.
Veni, vidi, vici.
|
|
|
|
|
CPallini wrote: Coding! Now that's a brilliant idea; who'd a thunk it?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I know I'm an innovator.
Veni, vidi, vici.
|
|
|
|
|
CPallini wrote: Another option would be using std::vector , and using the insert[^] method. I agree.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
1. determine the required size of the resulting container
2. Allocate a container of that size on the heap.
3. copy the elements to the new container.
If you have trouble following those steps, you better learn basic C/C++ by reading a good book or tutorial. A good one can be found at http://www.cplusplus.com/doc/tutorial/[^]
|
|
|
|
|
This is a simple program. I think in my opinion programming skill will develop through thinking, practice etc.
here your problem is simple. so try to implement self such a problem. i will give the logic.
1. allocate required array size for destination array.
2.copy the content from source array to destination.
I also agree with Richard and pallini
|
|
|
|
|
Hi every body
I develop an ActiveX control (.ocx) but I have a problem with the use of the ribbon resource in this project. I want to add the ribbon but i don't know how to do it.
|
|
|
|