So just add the centre (cx,cy) to your calculations
r * cos(theta) + cx;
r * sin(theta) + cy;
So just add the centre (cx,cy) to your calculations
r * cos(theta) + cx;
r * sin(theta) + cy;
/usr/bin/gdb
This is the command line debugger.
/usr/bin/ddd
This is the 'visual' wrapper around gdb.
You can use this to point at lines of code, insert breakpoints, examine variables etc.
> send me a program to remove unnecesary space from a string in turbo c++
Who gets to decide what is "unnecesary" ?
Read this
http://www.daniweb.com/techtalkforums/announcement8-2.html
Then make an effort.
> xss.exe - 4 error(s), 0 warning(s)
> void main
As well as being wrong (see previous posts, it should be int), you're specifically saying that NO value should be returned.
Yet later on (4 times to be precise), you have a
return 1;
etc.
This isn't void, so the compiler complains.
Oh, and post actual error messages as well so we don't have to guess at what you're seeing.
Does this even compile?
> return status;
I see no status declared anywhere.
> CA2CT mailHostConverted(mailHost.c_str());
This looks like it's stuck half way between a function prototype and a function call.
> conn.Connect(mailHostConverted);
I imagine this returns a status, why not test that to see whether the connect failed or not.
Since you've already included string, why not use std::string for all your strings rather than messing about with char arrays, with their fixed length, no overflow protection, do it yourself alloc and free problems etc etc.
> char temp[65535 - length + 1];
C++ doesn't have variable length arrays, you're relying on a compiler-specific extension to do this. static char temp[65535];
would be a quick fix hack in this particular case.
Well you can create a short string with
char s[2];
s[0] = ch;
s[1] = '\0';
Then pass that to atoi, though strtol etc are better long term bets.
A quick answer is to do
intVal = ch - '0';
http://www.daniweb.com/techtalkforums/announcement8-2.html
The first step would be to create a program which allows you to input a team / player, and print the information back to the user. Until that works, there is no point trying anything else.
> So better keep in mind that if the file is not present a new one with the same name will be created.
Not if you're opening it for reading it won't.
NAME
ftw, nftw - file tree walk
SYNOPSIS
#include <ftw.h>
int ftw(const char *dir, int (*fn)(const char *file, const struct stat *sb, int
flag), int nopenfd);
> The reason for this error might be that I am not allocating any memory for the pointer(correct me if I am wrong).
Yes, it has been allocated, but the memory which you're pointing at is read-only (meaning you can't change it). The variable p can be changed (say p="world"), but what it points at cannot be changed (you get the error).
> 1) Will the compiler places the string "name" in the stack segment of the memory
No, only p is on the stack, the string is somewhere else, allocated by the compiler.
In effect, the compiler does this for you. You just never see (or know) the name of the array it creates.
const char anon[] = "hello";
int main(void)
{
char *p = anon;
p[0] = 's';
printf("%s", p);
}
If you want something you can change, try
int main(void)
{
char hello[] = "hello";
char *p = hello;
p[0] = 's';
printf("%s", p);
}
Both your pointer and string are on the stack, and you can change the string via your pointer.
> 2) Will the string "name" be in the stack???
No, see above.
> 3) If that is the case why I am getting the error at the run time. The memory is anyhow allocated to the string.
Because the 'anon' string itself is not WRITEABLE.
Yes, it is allocated, no you can't change it.
> void main(void)
main returns an …
Basically, you look at the first element of each input list, and decide which one you want first.
You then remove that from the head of whichever input list and append it to your result list.
Keep doing that until both input lists are empty.
Please format your code
http://www.daniweb.com/techtalkforums/announcement8-3.html
Colourful, but variable spaced and unindented - bad.
Monochrome, fixed width and indented - good.
> char *url;
> url = sUrl.c_str();
Which got you
error C2440: '=' : cannot convert from 'const char *' to 'char *'
Understand that the c_str() method returns a const pointer for a reason, and that's to try and stop you from sneaking in the back door to change the string.
> char *url;
> strcpy(url, sUrl.c_str());
Which got you
warning C4700: local variable 'url' used without having been initialized
Yes, you used a variable before you initialised it.
Expect string data to be sprayed all over some unknown memory.
You can either allocate it as Lerner suggests,
Or simply have const char *url;
to satisfy the const requirements.
Or just do what GloriousEremite showed, and scrap the whole temporary used once thing.
If this is your first foray into graphics, you might want to get the libsdl devpack installed as well.
http://www.libsdl.org/index.php
The 's' is for "Simple"
> while(charbuff!=' ')
Maybe this is false on the first iteration, therefore i never gets modified and the function exits without doing anything.
> ........... some code
Post COMPLETE whole programs which show the problem.
Most efforts to snip out "irrelevant" code usually end up snipping out something really vital to the question at hand. This seems to be no exception.
> fscanf( fINPUT, "%s", &IP_name[j]);
> printf("%s\n", &IP_name[j]);
You're still using & where you shouldn't (on both of them).
Gah - beaten
So post your latest effort, taking into account mine and Narue's suggestions.
> # define EOF =-1
You should really have #include <stdio.h>
> can anyone explain me why the values are not swapped in the below code ??
Another problem is that your pointers are uninitialised - who knows, maybe they both point at the same memory location.
> char s[2];
How many buffer overflows have you written today?
http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html
Build up your own little graphics library of functions which you can call from the rest of your application.
Once you've mastered something like putPixel(), the rest should be pretty easy.
> ya thaxs it works
Rather too easy to break IMO
#include <stdio.h>
int swap ( int *a, int *b ) {
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
int main(void)
{
int a = 2, b = 3;
printf( "%d %d\n", a, b );
swap( &a, &b );
printf( "%d %d\n", a, b );
swap( &a, &a ); /* swap with itself */
printf( "%d %d\n", a, b );
return 0;
}
What do you get with the final line of output?
Is it what you expected?
> so according to you it depends on compiler ...
No, it's undefined.
http://c-faq.com/ansi/undef.html
You need to understand these cases.
1. Defined - every compiler does the same thing.
Eg. that && and || are short-circuited.
2. Implementation defined - compilers must document what they do
Eg. what right-shift >> does on signed negative integers.
Some implementations shift in zero, others shift in the sign bit. Both are correct, yet can cause problems for your code.
3. Unspecified - like implementation-defined, but undocumented.
Eg. the order of evaluation of sub-expressions.
4. Undefined - absolutely anything can happen.
You may get the answer you expect, you may get an unexplainable answer, you may get a crash in your program.
You may even get a crash (or worse) in your OS.
There is no point in even trying to understand what your compiler does, because whatever it does, it doesn't have to be consistent about it.
And everyone elses compiler is going to be different anyway.
Code which relies only on case 1 is good code.
Case 2 is OK, so long as it's well documented, but it would be much better avoided if at all possible.
Code which relies on 3 or 4 is on very shaky ground, and is best avoided.
I agree with Ancient Dragon, the code is broken.
You basically have variations of the problems listed here
http://c-faq.com/expr/index.html
Well for a value of 'n', how many recursive calls will there be?
Yes, you find the manual / help pages which describe the string class.
This will detail the public interface to the class.
Say perhaps
string foo;
foo.length();
> and i wonder if anyone can tell me what´s wrong with this code
Posting error messages helps.
> end1;
In your case, I guess you mean endl
That's lower-case "L" (l) at the end, not numeric one(1).
void interpolate(double FPAngle, double LiftCoef, double Angle, double LCoef);
//<< LOOK, misplaced ;
{
{
LCoef = LiftCoef[i-1]+((Angle-FPAngle[i-1])*(LiftCoef[i]-LiftCoef[i-1])/(FPAngle[i]-FPAngle[i-1]));
return;
} //<< LOOK - two open and one close
http://www.daniweb.com/techtalkforums/announcement8-3.html
Then do things like
- count opening and closing braces
- look for missing ; (or indeed as in your case, mis-placed ; )
http://www.cplusplus.com/ref/iostream/istream/getline.html
getline allows you to specify a delimiter of your choice, if it's a single char.
> it said pointer was best way to access dynamic arrays.
It's the only way.
But both variables have the same type.
car * catalogue = new car[c];
car *ptr = &catalogue[0];
All you've actually achieved is changing a 9-letter variable name (with some meaning) for a 3-letter variable name (with very little meaning). ptr[n] and catalogue[n] do exactly the same thing.
What you've also created is a dangling pointer problem. By having two variables pointing at the same memory you introduce the possibility of accessing ptr[n] long after you've done delete [ ] catalogue.
> car *ptr = &catalogue[0];
What does this achieve?
You can do this cin.getline(catalogue[i].make,20);
> delete [] catalogue;
You need to do this after you've finished printing the data, not before.
> however on the first run through the loop, the "make" of the car is not stored in the array
Maybe you typed a space after the input of how many cars
So the get() only got rid of the space, not the newline which would immediately satisfy the getline.
> array[i+1] *= array[i] ;
Since this is just short for array[i+1] = array[i+1] * array[i] ;
All the calculations involve undefined values because i+1 element is read before being written (in the absense of any other initialisation).
Start by stating what the problem is you're trying to solve rather than imagining using strstream is the answer. Tell us the problem you're trying to solve, not how to fix your solution.
Have you considered for example a vector of unsigned chars for storing your binary data?
> but the problem is that I can't access the streambuf "bp member" of my strstream.
The whole point of C++ is that internal representation is guarded by the class interface. If you're always smashing away the interface to get to the internals then you're really doing something wrong.
> but there's specific reasons why I was wanting to compile and run under Miracle C.
Because you're a masochist?
Like Dave said, Miracle C is a silly PoS compiler which looks great if your homework was "write a C compiler", but is utterly useless for anything more complicated than "hello world". Even crusty old TurboC had more features, and dev-c++ just wipes the floor with it. The bonus round is that dev-c++ is really $0 whereas Miracle C is $$$ nagware. Perhaps the real miracle is that people actually pay for that junk.
The only thing you will learn is frustration, and there's plenty of that coming your way even with a decent compiler.
If it's your school telling you to use that crud, then find a better school because they'll be incapable of teaching you anything useful.
Like
#include <iostream>
#include <string>
using namespace std;
struct record {
string C[3];
};
int main()
{
record param;
param.C[0] = "heading1";
param.C[1] = "heading2";
param.C[2] = "heading3";
int key = 0;
string data = param.C[key];
cout << "DATA: " << data << endl;
return 0; // zero is success
}
Or maybe
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
map<string,string> param;
param["C0"] = "heading1";
param["C1"] = "heading2";
param["C2"] = "heading3";
string key = "C0";
string data = param[key];
cout << "DATA: " << data << endl;
return 0;
}
> i finish writing my code but i have no idea how to write the pseudocode since classes and functions are involved
You're supposed to do the design (classes etc) and pseudo-code before doing the actual code.
They're the design and scaffolding you use to build the thing you really want.
> I thought the memory would be given back to the memory manager for general use.
That's what I said - it goes back to the memory manager within the program to be used in further allocation requests your program may make.
It's all virtual memory anyway, if your program stops using blocks of memory for a while, then the OS will likely swap that memory out to disk.
What about your source code, does it include windows.h before including any other windows header file?
> char temp[81]="";
But apparently your words are up to 1000 characters long.
Fix this, or fix your arrays.
> y[1000][1000]
1MB of unused space, just get rid of it.
It seems to me that you're likely to be blowing away your entire stack (and much more) before you've even begun.
Start with a small file of only say 10 short strings and verify that your algorithm works. Then scale it up to full size.
Try it with a file of only TWO words, and step through the code with a debugger.
> if (strcmp(a[d],a[lower])<=0)
Try using the x array (the one you read into) rather than something completely useless liike your a array.
> call to function 'Printf' with no prototype in function main"
Or maybe check the spelling. C is case sensitive, so Printf is not the same as printf
> but the memory that was used is not freed up
If you worked this out by watching task monitor or process explorer, then it wouldn't.
The program memory manager usually holds onto the memory for future memory requests from your program (which is relatively quick), rather than asking the OS each time (which can be rather slow).
> It waits only process number 1, and not number 2. Why?
Because you asked it to.
If you use -1 as the pid, then it will wait for any child, and return with the pid of the child which ended.
Put that into a loop until all your children have ended, then carry on as normal.
Well either you do it all yourself by reading
http://beej.us/guide/bgnet/ - to learn basic network programming
http://www.rfc-editor.org/ - to learn about the protocols which interest you
Or get a library to do a bunch of stuff for you, eg.
http://curl.haxx.se/
> Elapse Time Since Program Start Working
What do you mean?
The amount of time, as measured by the clock on the wall?
The amount of time the program has used?
If your program is low priority, say it's only using 10% of the CPU, there is a big difference between "user" time and "program" time.
> Board(GridDimension,GridDimension,Empty),//This line causes this error
So use
Board.push_back(GridDimension); // etc
within the body of the constructor instead?