Thank you Adak, I'll do that instead.
@Jim - probably irrelevant now, but good point, that's probably why it wasn't working.. it should have looped back round. Thank you!
Type: Posts; User: snoikey
Thank you Adak, I'll do that instead.
@Jim - probably irrelevant now, but good point, that's probably why it wasn't working.. it should have looped back round. Thank you!
Thanks for the quick response. Yep, the code with the function implemented is:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <complex.h>
#include...
Thanks for the reply.
if (strcmp(string,comparison)==0) comparison=strtok(NULL,delims);
is equivalent to
if (strcmp(string,comparison)==0)
{
I have the following code, which tokenises a file of the form:
Air density (kg/m3) = 1.225
Mass (kg) = 500
Engine power (HP) = 100
etc.
That's helpful, yes, I was treating it as a wildcard symbol. The whole of the text file I'm reading is:
Aircraft Parameters to be read. Do not add extra lines
or swap the order of...
Thank you, that's fair enough. I've tested arra, it works how I think it does, param[i] and param2[i], the tokens, are coming out ok, and if there's nothing else in the tokenising loop apart from...
I'm perfectly capable of debugging it, and have done, you're right about the size of arra so I'll change that, thanks. That wouldn't be affecting the program at this stage though as the file I'm...
Sorry, didn't mean to leave out that section - there are a lot of parameters so I thought it'd be simpler to just show three, but ended up snipping a bit out that I didn't mean to.
Attempt #2 at...
Oh, apologies. arra is the lines of the file. So arra[1] is line 1, arra[2] is line 2. That bit works alright definitely, because printing my tokens works fine, it's just the comparing and...
I thought since everyone on this forum has been helpful I would try and help back - I didn't know about the braces before yesterday - sorry if I insulted your intelligence.
I -did- check the...
True, but the long program is what my supervisor wants, and with this being my first month of C, I'm proud of it so far :P
I think my question now is:
Is there any other way of doing this other than using strcmp within the tokenising loop?
You don't need the brackets round the 'if' statement if there's only one line involved.. only learnt that yesterday from my project supervisor, this is just one part of a program that's over 1000...
Thanks for the quick replies. Ok, changed the loop and added a check for NULL.
I'm not completely sure what you mean by initialising the pointers - a quick search of the internet says after...
Beaten to it :P haha. *ideaS, or maybe there is just one to fix it!
Been playing with it some more and thought I'd tried this already but obviously not - changing the single quotes to double quotes in strcmp it now compiles fine but comes up with a segmentation fault...
Hi everyone,
I want to tokenise a text file with around 20 lines, and as the lines could be moved around, I want it to check the tokens for a certain word and if it contains that word, I want to...
It looks like you're right, thank you! Trying to find the website I got 'degrees' from I can't.. oh well, thank you!
Hi everyone,
I know this is the C board but hopefully someone can help.
I've been tasked with converting a FORTRAN program to C and am having problems with the 'DSIN' function, for example:
...
EDIT: thought I had a problem with this section cause it was coming up with seg faults again but turns out it was to do with trying to close a file that I hadn't actually opened.. sorry!
Great, thank you, it works now - probably not the prettiest code ever but oh well. The i problem made me wince.. stupid mistake.
float speed[50]={0.0};
speed[0]=0;
i=1;
while...
I want to initialise an array called 'speed' which has values [0 0.5 1 1.5 ... up to 50]. I'm testing it for 5 values in the array. I know I could do it manually but I would prefer to be able to...
That's useful - didn't realise a number could be used in that way. It explains a couple of problems I've had in another program. Thanks a lot!
@Adak - thanks :) that's why I thought I was so screwed to start with haha. I'm enjoying C a lot more now.
@Bayint - program works fine, I tried it initially without the &s and with various...
Completed, better version which sums parts of a struct.
/* Calculates total mass of an aircraft based on the sum of all of its parts by printing
all lines of a file data.txt into a...