It would be better if you actually posted your actual error message.
Rather than saying "an error", hoping we can be
a) bothered to run your code
b) actually end up with the same error message
Neither of these is guaranteed.
It would be better if you actually posted your actual error message.
Rather than saying "an error", hoping we can be
a) bothered to run your code
b) actually end up with the same error message
Neither of these is guaranteed.
> Try this..Does it do your job:
Well it might, if you included stdlib.h as well.
Then you might be able to call malloc without having to resort to dangerous casting (it's REALLY dangerous without a prototype, and essentially useless with a prototype).
Why is it dangerous?
Well Dorothy, without a prototype, malloc would be implicitly declared as returning int. On machines where pointers and integers have different sizes, that's one nasty bug waiting to bite. Not that you would see that at compile time, the cast ensures a dose of "STFU" to the compiler.
Omitting all the optional braces might be OK, so long as your indentation is top-notch. Yours isn't, so it's more bugs in hiding.
To further what Tom Gunn said, if you changed char name[25]
to char *name;
then the second printf would immediately be very wrong indeed, and not just ever so slightly odd.
Lemme get this straight, you wrote some code but you don't have a really good idea of how it's "SUPPOSED" to work?
This is basically voodoo programming; write some mystic runes, sacrifice a goat, compile it and when it crashes scream "the gods have spoken!".
Get a debugger, put a breakpoint at the start of the code and MAKE SURE for yourself that it:
a) copies the old vector in its entirety,
b) appends exactly one element,
c) has exactly the right amount of space for all of the above.
This is a trivial program, if you can't debug this, then you're basically S-o-L as a programmer.
Sure I could tell you what's wrong, but next week you'd be lying at the bottom of the next hole you've dug for yourself wondering exactly the same things (wtf happened, where's my daniweb, post and relax).
Congratulations.
But using code tags would have been a good idea, if you wanted people to read it.
Not enough?
How about looking at your needlessly complicated push_back()?
Your code is wrong.
> asked and answered at least half a million times since Daniweb went live.
For the millionth time, stop exaggerating ;)
DaniWeb IT Discussion Community Statistics
Threads: 199,393, Posts: 951,087, Members: 601,466, Active Members: 85,978
> Why yes, there is indeed a way.
Where there is a will, there is a way.
As in
"Will you do my homework" - "no way!"
You read a line
You validate a line
If the line isn't what the user was asked to provide, then print an error message and read again.
Read the link (or your book). Your syntax is broken.
Is there a particular reason why you're doing this the hard way, with a "roll your own" per-character input?
Because there are standard library functions to read a whole line for you.
> "program to swap two no. using third variable"
A better question would be:
"How to swap my idiot teacher of 1970's assembler tricks with someone who has a clue about programming in the modern world".
> I am trying to work learn thread programming in C.
Mmm-kay,
> I have my turbo C installed and its working fine.
You're stuck then.
> Please do shed some light on how to configure my Turbo C to work with threads.
Delete is the only config possible.
Followed by install of a modern compiler for your modern OS, trying to use a modern API.
Is this still a console program (the answer is in my reply to one of your other threads), or have you moved onto a GUI program?
GUI's are typically event driven, so you don't read the keys as such, but you do get key events as part of the normal flow of events.
Either set the length of the vector before you start, or use push_back() to add each new cube as you go.
http://www.daniweb.com/forums/announcement8-2.html
Read this, make an effort, post that attempt and then ask a specific question.
Don't just dump your assignment on us and then go party, hoping to have a nice finished program sitting in your in-box.
> Please its urgent.
You don't say, really?
http://www.catb.org/~esr/faqs/smart-questions.html#urgent
Use fgets() to read each line.
Use sscanf() to parse the line (or better yet, strtod).
> well i am planning to record information in a database and the data can be accessed via the web in a well formatted web page.
That has to be the most bone-headed idea going.
"I know, lets publish all my keystokes on a web page for all to see - ohh, passwords, yummy!"
If you want to do something useful, write a program which finds keylogging malware, rather than adding to the considerable amount of pond life which is already out there.
delete &capacidad;
delete &indice;
delete &datos;
All these are wrong.
a) you don't call delete AT ALL unless you called new.
b) a new [] is matched by a delete []
So delete [ ] datos;
would be the only thing needed here.
All the files are in the same directory?
If so, all you need to do is add the two .cpp files to some kind of project (or makefile), and then build.
> cannot find -lfunctions.h".
-l is for libraries, not header files.
Like I said, in a simple case with everything in the same place, you don't need any additional compiler flags.
Oh, and remove the namespace from the header file. In future, if someone wants to use your header files, they may not want the namespace. There is no "undo" once a namespace has been added.
Instead, write
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <string>
// don't do this using namespace std;
int do_action(std::string a, std::string filename);
#endif
using namespace std is a pretty lazy habit anyway. You might try something like
using std::cin;
using std::cout;
to cut down on the really repetitive stuff, and use the full std:: approach for everything else.
When you start using other namespaces, the transition will be less harsh.
> As a nasty hack this works fine but it takes a long time (> 10 mins) to run the code through enough repetitions.
> For my project specification I really need this to be much, much faster (< 5 mins hopefully)
Why does a program which runs only once per year need optimising from 10 minutes to 5 minutes?
It's not like you're going to be mass reassigning schools on a weekly basis or anything.
> ORDER BY capacity ASC
Does this actually do anything useful?
I see why you select schools with capacity, but why then go to the trouble of ordering it as well?
> kids = cur2.fetchall()
> bestkid = kids[0][0]
I'm guessing the LIMIT 1 in the previous line means fetchall only fetches 1 row, and not potentially up to 17000 rows.
Since you're only ever interested in the first row anyway, what about fetchone() ?
Likewise, isn't all this redundant anyway? What is in the nearest_pupil result on the previous line anyway (which goes unused at present).
Rules on where to post
http://www.catb.org/~esr/faqs/smart-questions.html#forum
Rules on topic titles
http://www.catb.org/~esr/faqs/smart-questions.html#bespecific
Rules on language and spelling
http://www.catb.org/~esr/faqs/smart-questions.html#writewell
And so on...
Edit:
oh, and your cprogramming.com thread has been reopened.
It lacks imagination, but did you try this?
http://www.google.se/search?q=png+to+xpm&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-GB:unofficial&client=firefox-a
What - that you can't use a float to subscript an array?
The error message should have been pretty obvious.
Array subscripts are integers.
> saveToFile(*client_file, *cd);
Neither client_file or cd are initialised.
Something like this
client_file = fopen("data.txt","w");
if ( client_file != NULL ) {
saveToFile(*client_file, &client);
fclose( client_file );
}
Oh, and make sure you prototype your functions before calling them.
Had you done so, this would have generated warnings.
Actually, I'm surprised it didn't anyway.
Use a different separator.
Eg.
sed -e "s@DATEST\@$DATESTART@g"
I can't figure out where the real separator is in the middle of the expression.
But you get the idea.
sed -e "s/DATEST\/08/25/2009:07:41:41/g"
One or more of the / in your dates needs escaping.
One function to write the struct to a file.
Another function to read the struct from a file.
For each field, use the appropriate fprintf or fscanf conversion function.
For extra robustness on reading, use fgets() to begin with.
Languages like C and C++ are far too flexible to diagnose ALL possible run-time faults at compile time.
If you post an exact run-time error message, we might be able to tell you where to start looking.
Dunno, I can't see your code from here.
It would work if you did everything right, but since it doesn't, I'm guessing you need to fix something.
You've got
#include "somethingElse.h"
#include "DoTestData.h"
The last thing in somethingElse.h is the real cause of the problem, and it will be missing the ; in question.
> This is just a skeleton.
In other words, a complete waste of time.
Post an accurate facsimile of your actual problem, and you might get some useful answers.
Post random dribble in a half-assed attempt to paraphrase the problem and you're going to get equally off-target and useless answers.
> void processone(int delay);
This is an int
> processone(av[1]);
This is a char*
> void processone(char avinput)
This is a char
Making prototype AND definition a char* as well would go a LONG way.
Post some more code, for example all the other declarations of variables used in this code.
Or just be more careful writing out the existing data....
Your struct contains strings.
These are not simple objects, they contain pointers to where the data is stored (elsewhere). Simple write() functions don't know this.
Which OS?
Which webserver?
Which firewall?
You know, basic information about your setup.
You need to post some context.
What is error 468, (I've no idea, each compiler is different).
Which line is that on?
Does it happen when you compile the program or run it?
Like so
#include <stdio.h>
#include <string.h>
struct student
{
char studName;
int studID;
char sex;
char email;
int mathsScore;
int englishScore;
int scienceScore;
};
void readData(struct student data[]);
void printData(struct student data[]);
int main(void)
{
struct student data[20];
readData(data); // pass parameter
printData(data);
return 0;
}
void readData(struct student data[])
{
// now a parameter struct student data[20];
int i=0;
FILE* input;
input=fopen("inputfile.txt", "r");
while((fscanf(input,"%s %d %c %s %d %d %d", &data[i].studName,&data[i].studID,&data[i].sex,&data[i].email,&data[i].mathsScore,&data[i].englishScore,&data[i].scienceScore))==7)
{
i++;
}
}
void printData(struct student data[])
{
// already called it once, readData();
// a parameter struct student data[20];
for(int i=0;i<20;i++)
{
printf("%d.%s\n%.6d\n%c\n%s\n%d\n%d\n%d\n\n",i+1, data[i].studName,data[i].studID,data[i].sex,data[i].email,data[i].mathsScore,data[i].englishScore,data[i].scienceScore);
}
}
So what is your question?
> vararray[v+1]==NULL
Well if vararray is an array of char, then testing the nul character (as opposed to the NULL pointer) is what you should be doing.
As in vararray[v+1]=='\0'
Aww, and I was hoping they might have to figure out the sub al,'0'
thing for themselves....
Better yet, tell US what you found out, how you solved it and then mark it closed.
Give something back.
mov ah,1h ; input number
int 21h
mov dl,0ah
The result is returned in al
http://www.ctyme.com/intr/rb-2552.htm
Double what you had.
The more capable it is, the longer it will last and the quieter it will be while it is running.
insert() returns a value, which you're ignoring.
> file.write(tit,30);
If you're going to write 30 bytes, then you need char tit[30] = "Title";
otherwise you're reading uninitialised memory and storing up who knows what kind of trouble.
> file.read(test,4);
This won't have a \0 at the end (unless the file happens to have a \0, which seems unlikely).
Read 3 bytes, and then set test[3] = '\0';
Also, between WRITING and READING, you need to flush()
> My requirement is that I add a very small value of the order 10^-7 with a relatively big value, say 36.63
floats have about 6 decimal digits of precision, doubles about 15.
10^-7 is more than 6 digits away from 36.63 so your really small number is effectively zero.
Using double will buy you some head room, but won't solve the underlying problem.
Two choices
- use a math library with arbitrary precision like GMP
- rearrange your expressions so that precision is preserved as long as possible.
Eg.
float small[10] = { };
float big;
for ( i = 0 ; i < 10 ; i++ ) big += small[i];
would become
float small[10] = { };
float big;
float smallish = 0;
for ( i = 0 ; i < 10 ; i++ ) smallish += small[i];
big += smallish;
Each small by itself is too small to affect big, but by combining them all together you end up with something which can affect it.