|
Is there a way to do <title>?
|
|
|
|
|
|
|
I am trying to read two cities with their Lat and Longs from a text file so I can compute the distance between them.
the text file format is San Francisco 37:47:48n 122:24:57n Honolulu 21:16:25n 157:49:13w
can anyone tell me how I can read from text file so I can do the math
or does anyone have a similar example out there that they have done.
Thanks
|
|
|
|
|
Split the string into words by looking for spaces, and put this into an array of char * s. Then look to see if the first character of each word is a number or not and if so, remove the end character and split it up by the colons; then simply use atoi() to convert these into numbers and do whatever you want with them
Hope this helps,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Thanks for the quick reply
what would the code look like to do that, the array I know but atoi() I don't.
what would you do?
Thanks
|
|
|
|
|
After some dabbling in my C IDE, I have come up with this to split the string up and put the lat/longitudes in an array:
char text[] = "San Francisco 37:47:48n 122:24:57n Honolulu 21:16:25n 157:49:13w";
char *input = (char *)text;
char **data = NULL;
char *ptr = NULL;
int i, datacount=0, curr=0, len;
for(i=0;i<(strlen(input)+1);++i) {
if(input[i]==' '||input[i] == '\0') {
len = (i-curr)-1;
ptr = input+curr;
if((ptr[0]>('0'-1))&&(ptr[0]<('9'+1)))
{
datacount++;
data = realloc(data, (datacount+1)*sizeof(char *));
data[datacount]=(char *)malloc(len);
strncpy(data[datacount], input+curr, len);
data[datacount][len]='\0';
}
curr = (i+1);
}
}
You can do something similar to split the numbers with the colons - the atoi() reference is here.
Hope this helps!
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Thank you I really appreciate the assistance, I didn't know there where people out there so willing to help.
Thank you! Thank you! Thank you!
|
|
|
|
|
No probs
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
2 questions
what do I need to do to finish this?
how would I pull this info if it was in a text file?
Thanks
|
|
|
|
|
- You need to do whatever you need to do with the lat/longitudes stored
- You would use the
ReadFile() function (documentation here).
Hope this helps,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
I am two blocked
I have an error "invalid conversion from void to char" on the:
data = realloc (data, (datacount +1)*size of (char*));
|
|
|
|
|
Cast it to a char** by changing that line to:
data = (char **)realloc (data, (datacount +1)*size of (char*));
That should sort it
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Hi,
I have an application that I have embedded an OpenGL scene into a CScrollView, the problem I am having is when I move the scroll bar, the OpenGL Scene doesnt move with it. What am I missing to cause the scene to move with the scroll bar movements. I think I am missing an openGL call that links the windows scrollbar position to the OpenGL Position.
Any help would be greatly appreciated. Thanks in advance!
|
|
|
|
|
Hi,
I have a MDI application in VC++ 2005. Once I linked to new common Vista controls 6.0, third party buttons stopped working and its not supported anymore, so I have to switch these buttons to windows buttons. I have a class MYGraph derived from ThirdPartyGraph, and in CMyGraph::BuildPage(), I used CButton::Create method to dynamically create the buttons... I do come up with an error from third party which basically says bad ChildProcessControl... If I apply this same concept on simple Dialog based application, I have no problem.... Does anyone have an idea how to get wround this since the buttons I am trying to create aill be on a frame which is derived from third party?
Thanks
|
|
|
|
|
So I'm using the CMFCOutlookBarTabCtrl control from the VC Feature pack. In it, I'm putting a couple of custom controls. Problem is that the controls aren't being redraw properly: after resizing the CMFCOutlookBarTabCtrl, they are white. I have trace messages in my OnPaint I know that that function is called. I watch the messages with Spy++, all goes well. When I put another control in the CMFCOutlookBarTabCtrl it works fine (standard windows control like a button but also for other custom controls). When I show the custom control outside of the CMFCOutlookBarTabCtrl it works fine, too. So it looks like my control is being drawn over after its WM_PAINT handler has been called. Oh, when I put in a WM_MOUSEMOVE handler and do an Invalidate() in there, it works too. Anyone who is still with me after this description and who has an idea on how I could go about debugging this? Thanks.
|
|
|
|
|
Hi every one!
Is this a safe way to define key structure.If not then how'd it be safer
Thanks!
typedef struct _key
{
struct p1
{
struct p2
{
unsigned char a1[128];
unsigned char a2[8];
};
unsigned char b1[64];
unsigned char b2[64];
unsigned char b3[128];
unsigned char b4[64];
unsigned char b5[64];
unsigned char b6[64];
};
}
KEY;
|
|
|
|
|
What do you mean safe? Type safe, thread safe, OO safe, exception safe or just proof against terrorist bombing?
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
I mean safe by the fact that these arrays are big and many, or would it be a problem in memory ?
Also is it Thread safe?.
And is it OO safe because i will use it in a class
Thanks!
|
|
|
|
|
It wouldn't be a problem in memory, it will just use up quite a bit of it And being thread safe is only a problem if you have two or more threads trying to access the same bit of data at the same time. It is perfectly OO-safe unless it is a private/protected member and you are trying to access it from outside the class
Hope this helps,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Dennis L wrote: safe by the fact that these arrays are big and many
That will depend on what error checking you have active when you allocate the structure, rather than on the structure itself and how much memory is available of course.
Dennis L wrote: Also is it Thread safe?.
Not as presented. There's nothing inherent in this structure to prevent multiple contexts accessing it asynchronously.
Dennis L wrote: And is it OO safe because i will use it in a class
Not as presented. The data members should ideally all be private (data hiding), all access should be via accessor functions, default constructirs, copy constructors and possibly equivalence/comparison operators may need to be provided.
Having said that it's a good start to get your fundamental data structures right for the job. All the rest can then be added and you know you're not wasting your time.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
About the OO safe question
i will use it like:
class MYCLASS
{
...
...
public:
KEY k; or KEY *k;
...
};
|
|
|
|
|
Hmm, that's not very OO. Google up some terms like 'data hiding' and 'design by contract' to get ideas on 'better' ways.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Sorry! If KEY is a private member?
Or what if i do it like
class MYCLASS
{
...
...
public:
void Get(KEY *k);
...
};
// in cpp
void MYCLASS::Get(Key *k)
{
// Do operation:
}
int main()
{
MYCLASS g;
KEY k; // key is empty
g.Get(&k);
//key is filled
// Do operations with k
return 0;
}
|
|
|
|
|
Yep, you can do it that way. It's not really the usual way to do things but you can do it that way if you wish. It would be more normal to write the functions that do operations with k as members of MYCLASS which use the private member k to do their work and return results to their callers e.g. Key validity.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|