it's string which leaks away with"
string = NULL;
true - that should be free'ed! Thanks!
"but for certain strings, it segfaults when exiting the function."
Is it always the same string(s)? Have you run it in the debugger and attempted to work back from the segfault to identify the problem...
Thanks very much for the replies,
To first respond to the second reply, this is to run on different 'NIX machines, using gcc3.X. Mostly tested on LInux, but there are a few Cygwin users. This is used for 1 to 5 minute simulations of building thermal response. The main f77 program dates back to...
Sorry if this has been addressed in previous posts - I quickly searched, but couldn't fin and answer ...
I'm statically linking a C library to existing fortran77 code. I need to pass, from a higher-level C function, a f77 string to copy over to the C side. I've written this function that...
Thanks Salem, maybe I'm not getting something ... in no way am I interested in setting the maximum number of characters in a scanned string. The string could be '0.1' or '0.001e+000'. All I want to do is avoid unexpected behavior if ever some gibberish gets inserted in some way in an ASCII file...
hmmmm ... if the string contains gibberish that can't be part of a valid float, then you're right: *endptr will refer to the first non-valid character. Yet if it's '0', then *endptr seems to be NUL - always. I've tried with preceding white spaces, tabs, etc. it's still NUL. I'm guessing here...
Thanks Salem!
I had come across strtof in the atof man pages, but apparently hadn't tested it enough to get a better sense of its worth.
Consider the strtof prototype in Salem's response. If nptr is, let's say '0.0000e+000', then strtof returns '0' (meaning there is no conversion), yet *endptr...
I'm sorry if this sounds totaly amateurish (and I guess easy to answer), but can't '0' be considered as a float or double? I'm parsing input lines to make sure all tokens are valid floats (e.g. 0.00001e+002). I do this by checking the returned value of 'atof' for each scanned token 'string'. If...
Hi to all,
I noticed that ascii input files to a Linux C program I share with colleagues (we're in research, not professional programming) weren't being properly scanned. After a few days of debugging, we came to the conclusion that this had to do with semi-invisible characters, likely being...
Salem,
Yes, I understand your static vs. dynamically-allocated array-as-a-argument case with the foo subroutine. You're right, it doesn't matter for foo.
That's not my point (excerpts from 'man malloc'):
"Crashes in malloc(), free() or realloc() are almost always related to heap corruption...
I want to avoid memory allocation/deallocation function problems by first checking (at the start of each function) if a pointer already points to some allocated memory in the heap (before trying to 'malloc' it), or not ...
All the functions that 'free' pointers in turn set the pointer to NULL...
Hi,
I often use C for data handling, with the data being sent back and forth from someone else's parent program (so I rarely write my own read/write functions). I have to update what I consider an error-prone way of scanning and parsing a given file (known format).
I've gone through a number...
I have a curious, follow up question to my initial one:
In the F77 program I'm modifying, some C header files are added after the program declaration:
PROGRAM COUNTHUMANBRAINCELLS
#include "human.h"
...
CALL CFUNCTION()
...
RETURN
END
In my previous posts, I suggested a simple...
OK, a few minutes after the last post ... quite simple, but if any hardcore C programmers see a problem with this let me know:
In a "header file", following the usual struct definitions, e.g.
typedef struct
{
int braincells;
} human;
declare 'global variable':
human*...
I left something out: what I really want is a struct POINTER which is global to all C subroutines, allowing me to use malloc in one (the first) C subroutine I use, then have all the other C subroutines access the same dynamically-declared array of structs. So a few changes to what you posted ...
I need to integrate a few C subroutines within a f77 program. I've tested on many occasions passing 2D arrays back and forth between C and f77 before, so that's ok. However, in this instance, there's a lot more data to be handled by the C code (data that the f77 code doesn't really need to...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.