Correct me if I'm wrong, but isn't scanf a dangerous way to read in a string? Wouldn't it have the same issue as gets? I'm not seeing a length arguement (I guess you could try something like...
Type: Posts; User: Raptor007
Correct me if I'm wrong, but isn't scanf a dangerous way to read in a string? Wouldn't it have the same issue as gets? I'm not seeing a length arguement (I guess you could try something like...
I could be mistaken, but I'm pretty sure the direct manipulation required to partition and format is very operating system dependent. You might get better help if you gave us your OS and compiler. ...
Hehe, you're asking that in this section? That's kind of like going to a dog show and asking if anyone there likes dogs...
(Yes. I like C.)
Try rebooting your machine, in case some program is holding that file open and refusing to let other programs access it (not too likely, but just in case).
Also, what OS and compiler are you using?
It's safest to specify whether you're reading text or binary, using "rt" or "rb", rather than leaving it to your compiler to decide. Same with writing, "wt" or "wb". But this isn't really your...
I haven't put it into my compiler to check it, but it looks like you've got the hang of it so far.
EDIT: If you check a malloc and find there wasn't enough memory, you should probably do...
I agree, it's very unclear what you're trying to do. Perhaps you were looking for something like rewind?
By the way... why are you writing plain text to a .exe file?
Sometimes the easiest way to loosen something's grip on a file is to just reboot the machine. If that fails, you could try a virus scan. I use http://housecall.trendmicro.com because it's free and...
True, this will make it work, but it's no longer doing anything in parallel.
Although, I've never heard of a statement that simple setting everything up in parallel. Even MPI, which is pretty...
Yeah Machoscorpion, that's probably how I'd do it too. For just checking if the file exists, I think read-append and just plain read will have the exact same effect, but since we have no intention...
This is a command-line program looking for arguements. Hitting Run in the MSVC environment won't give it any arguements by default (maybe someone else knows a way to do that).
You can open a...
I'm sorry about that, you're right that I shouldn't have used gets in my example. My post was mainly supposed to show that he needs memory allocated to use any such function (giving some code to...
What is wrong with you, and what are you talking about?
I even left out the cast, just for you.
Btw, it was nice of you to post to this guy's thread just to flame me and not even let him know...
It sounds like he's used to other languages which do not require you to set a maximum string size initially. This is a familiar feeling, I've been there too. :)
The problem is, gets() and...
In your example, no, I wouldn't use casting. I use casting when void * (or void **, void ***, etc) are involved. It's especially useful when lots of code separates the declarations from the actual...
Something you might not be used to... all strings in C are arrays of characters, with a null terminator character telling it when the string ends.
Therefore this:
char string[100];
...
Well, my idea behind safefree was originally this:
void safefree (void **pointerPointer) {
if (*pointerPointer) {
free (*pointerPointer);
*pointerPointer = NULL;
}
It doesn't have to be an array, I just figured you had an array of values.
Here it is with just plain sequential integers:
// Loop through all values in the array.
for (i = 0; i < max; i++)...
You could try something similar in C:
struct Array {
void **elements;
int size;
};
No, no, no... that would print the characters backwards, he wants to print the LINES backwards with each string intact.
Something like this should do it:
#include <stdio.h>
#include...
Try something like this:
// Loop through all values in the array.
for (i = 0; i < size; i++) {
// Print the current value.
printf ("%i", array[i]);
I think I fixed it! :)
I have a function that copies a string to a new size, and I was using it with strlen (oldStr) to copy strings down to the minimum size needed. Unfortunately, my malloc was...
Ah... I started suspecting it wasn't that particular buffer when commenting out the free statement gave me errors in the free statements that are inside fflush and printf. Plus it's a pretty...
Hey, I'm writing a C program that uses a whole lot of malloc and free commands. I've run into a snag where partway through execution, it fails on a free command. However I've checked thoroughly by...