So I have a function written as follows
inline
tSomething::tSomething(map<int, tSomethingElse* > const & Points,
tWhatever const * a_ptr,
int ID,...
Type: Posts; User: browser
So I have a function written as follows
inline
tSomething::tSomething(map<int, tSomethingElse* > const & Points,
tWhatever const * a_ptr,
int ID,...
Sorry guys, I have spotted another mistake in the code. The above was working fine because all the types ("X") in the the file were the same. It turns out if they are different like here;
4...
Yes, it just needed to be read once. But I think the problem was that after fscanf, fgets still went to the beginning of the file to read again. If I changed the '4' to an 'X' the fgets still printed...
So I 'fixed' it by doing this;
fgets(buf, sizeof buf, input);
N=atoi(buf);
printf("N has been read as %d\n", N);
fgets(desc, sizeof desc, input);
printf("Description has been read...
Thanks, I changed that and my output still looks weird, but so far is the only one that has printed 'user description' in some form to the screen
N has been read as 4
Description is ...
Okay guys, I may have broken it again.
Quick recap, I am trying to read filename.xyz
4
User description
X -0.906801 0.569837 0.066005
X 0.956585 -0.258900 0.342064
I have seen this around but have so far not been able to use it
Thanks guys, I think it was the "type" that got me into trouble. I also used a function in order to read N first
int findN(FILE* input)
{
int N;
fscanf(input, "%d", &N);
return(N);
}
Isn't that what I am doing here;
int main()
{
FILE* input;
int N;
char type;
int i, j;
double finalvalue;
Jim - I am using malloc after I have read the file...well, while I am reading the file?
anduril - I moved
double array[N][3];
double *ptr;
to above my malloc line. Still prints "N is...
So if N needs to be read from a file and the array size needs to be set to 3 x N how would I do that without getting this problem?
Thanks
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
double finalcalc(double array[][3], int N);
int main()
{
FILE* input;
Thanks Jim, I have fixed those. Still getting the same problem.
I have read a file into an array in my main and it has done so correctly (after help from this board a few threads down). I now need to perform arithmetic with that array in an external function....
Thanks guys, got it working again. I think I was getting confused with the "while" part of the code and it is now working without that.
And sorry Adak, next time I will try to post more of the...
Thanks for all the suggestions, but I am still having trouble.
I have tried
fscanf(input, "%[^\n]", &desc);
and
i have an input file that looks like this (intentional whitespace);
456
Unspecified user input up to 100 characters
X 4 5 6
X 7 8 9
X 1 2 3
My code runs at the moment using fscanf which...
It isn't global. Both arrays are pointers to double but they have been individually malloc'd (if that makes a difference).
By 'call split_array' I meant that I am not passing it through an...
My code looks like this at the moment;
for (j=0; j<bfun_lines; j++)
{
printf("Attention! BEFORE main split array %i is %lf\n", j, split_array[j]);
}
Thanks very much for looking through it! I realise how tedious it must be.
@hk;
#1 : I am looking at the location for a \n and incrementing if it is stored. This way of doing it accounts for...
Thanks...
I used a printf statement to see where the segmentation fault occurred and found it was an uninitialised pointer...
for some reason though...fixing it has led to a complete breakdown...
Really sorry to post such a long code. But I have no idea where this segmentation fault is coming from.
It prints fine until it calls splitme function and then i get a segementation fault.
...
I did that and it is still not compiling.
Okay...
so for this, would it be possible to write bfun_split into the passing *array and call it like that?
edit: I tried
i=0;
for (i=0; i<array_size; i++)
I did it here...
double ReadFile(FILE *filename, int num_lines, double *array)
{
int i;
rewind(filename);