In the folllowing code, I have an array of characters called 'data', and I want to scan through it and write characters to a file ONLY if they are not a digit or a space. I can't get this to happen;...
Type: Posts; User: shadow1515
In the folllowing code, I have an array of characters called 'data', and I want to scan through it and write characters to a file ONLY if they are not a digit or a space. I can't get this to happen;...
I got it working by rellocating to t * sizeof(int) for t that increases each time the loop executes to add more to the array.
Thanks for the help, the problem was that I didn't realize exactly...
Since this code already takes place in a loop with a variable that counts up with each loop, would it be correct to use
num1 = realloc(num1, t * sizeof(int));
since t is growing by one...
Basically, I've got two pointers that I want to fill with data read from a file, and I want my program to allocate memory to the pointers based on how much data there is (since it will not always be...
It does, thank you, you did a lot to clear up my understanding of structures and pointers.
Thanks for the information. I think I'm starting to understand a little better now. I ended up simply declaring the position array as int position[2] because I already knew what size I wanted it to...
As far as I'm aware, there is no more allocation code. I don't even know enough to know what that really means. To show more code, here is how I use the first structure element that works:
...
I'm just learning structures, and I'm having some trouble. The following is the structure I delcared globally:
struct creatures
{
int *position;
};
and the next is when I declare members...
Thanks, that did it. I figured fscanf wouldn't do it, but I didn't know about sprintf.
I'm writing a program and I want to put a written file inside a for loop. For each run through the loop, I want to write to a different file. How do I do this? Here's the code:
...
I wrote a simple program to print a grid of 0s on the screen, and move a 1 around with user input from the keyboard (eventually, the goal is a "snake" game).
It works fine. I hit W, it moves the...
Oh, now that I've already posted my entire code, I'm having another issue and I don't quite know how to resolve it. After adding getchar after the scanf in my ask function, it works fine. Another...
Ok, adding getchar right after my scanf made it work fine. Thanks for your help!
Ok, here's my entire program. It runs perfectly fine besides automatically closing after it runs, but if you have any other suggestions those would be greatly appreciated as well.
#include...
In the beginner tutorial on this site, it mentioned that adding the line getchar(); right before return 0; at the end of the main function would keep the program running until the user hit enter.
...