Laserlight, thanks for you help. I removed the line:
sum = SUMARRAY(x, 4, i, total);
and replaced it with;
SUMARRAY(x, 4, i, total);
That cleared everything up, is that because I already...
Type: Posts; User: ginom71
Laserlight, thanks for you help. I removed the line:
sum = SUMARRAY(x, 4, i, total);
and replaced it with;
SUMARRAY(x, 4, i, total);
That cleared everything up, is that because I already...
OK, thanks everyone for the help. So you're saying that I need to write it out like I would for a function, which I did (just for practice). See below:
#include <stdio.h>
#include <stdlib.h>...
OK, so that while loop won't compile in the main body of the code. I wouldn't normally use that code to sum the elements in an array anyway. I'm just pretty lost when it comes to defining this in a...
Thanks again. I read that people have had trouble with recursive functions in macros. I'm not sure what the benefit is except for maybe simple computations.
So I took your suggestion, and I wrote...
What is the syntax? Do you write it like you would normally for a function prototype? This is what I have:
#include <stdio.h>
#include <stdlib.h>
#define SUMARRAY(x, y) \
(while(y!<0){\...
Hi all,
Is it possible to include a for or a while loop in a macro? I have an assignment that says to create a macro that will sum the elements of an array, but the book, obviously, didn't show...
Thanks for the help! I was trying to experiment to see if I could read the input and automatically copy the string. So I have it working, but the buffer still has some characters(not sure how). See...
Thanks for the response. I used your suggestion of fgets, and unfortunately it's not working. Also, shouldn't there be parentheses after "sizeof"? Thanks again for the help.
while(fgets(choice,...
Hi all,
I'm having trouble with a function that is supposed to update records. I have copied it below:
void updaterecord(FILE *fptr)
{
int record;
int choice;
char newname[30];
Sorry, I forgot the code to write the new data into the file. It works now.
I have also tried the following:
void eatnewline(void) {
int x;
do {
x = getchar();
} while(x != '\n' && x != EOF);
}
Thanks again for the help. OK, I've changed your code around a little to fit my program. This is the new function prototype to insert a new record. See below:
void newrecord(FILE *fptr)
{...
Thanks for that. Why do you set name[index] to zero?
I am, but the problem is with input like "Sledge Hammer" and then 7.50 for cost. I need to figure out how to enter strings that have spaces, and then input value for other variables.
Here's a sample of code:
void newrecord(FILE *fptr)
{
struct inventory tool = {0, "", 0, 0.0};
int recordnum;
printf("Enter new record (1-100): ");
scanf("%d", &recordnum);
Is it possible to scan strings with spaces, and then other unlike int variables. For instance, if I wanted to input the name of a tool, then it's price, how would I differentiate between the two in...
God, I can't believe a typo was causing me so much grief! Thanks for spotting that! It's working now. Thanks again for your help.
OK, I used the following line to close it in the function.
fclose(cfptr);
When I ran the program, I still got the message "File could not be found".
I do try to reopen it within the main...
Hi all,
I've just learned how to create files in C, and I have an entire program written for an inventory. The code compiles and runs, the problem is that the file that I have created won't open...
hehe. Syntax error on my part, must have had a brainfart. Thanks for pointing that out!
I tried this, but it didn't work. The program just ignored my loop and continued executing.
do{
printf("Enter any Fahrenheit temperature above 0 and below 212 degrees: ");
scanf("%f",...
yes. When the user is prompted to input a degree between 0 and 212, lets say they enter "-17". The next line that prints is "Please enter a number above 0", then the user is prompted again to enter a...
Hi all,
I wrote a program that converts Fahrenheit temperatures to Celsius temps. I would like to have the program account for incorrect input (like a degree higher than 212 or less than 0). This...