hi can anyone tell me how to write the output of this code to a file??

#include<stdio.h>
#define MAX 10
char array[MAX];
void main()
{
void addvalues();

addvalues();
}

//funtiocn that will allowe the user to add the values
void addvalues()
{
	printf("------------------------> Insearting List Elements <---------------------------\n");
	int i;
	printf("Enter you the 10 elements\n");
	for(i=0; i<MAX; i++)
	{
		printf("Enter element number %d:\t ", i);
		scanf("%s", &array[i]);
		printf("\n");
	}
}

Edited 6 Years Ago by darkdai: the title was typed wrongly

hi can anyone tell me how to write the output of this code to a file??

#include<stdio.h>
#define MAX 10
char array[MAX];
void main()
{
void addvalues();

addvalues();
}

//funtiocn that will allowe the user to add the values
void addvalues()
{
	printf("------------------------> Insearting List Elements <---------------------------\n");
	int i;
	printf("Enter you the 10 elements\n");
	for(i=0; i<MAX; i++)
	{
		printf("Enter element number %d:\t ", i);
		scanf("%s", &array[i]);
		printf("\n");
	}
}

No, the file doesn't produce any output.

void main() is incorrect
scanf("%s", &array); is incorrect.

Comments
WHY is it incorrect?

Are you running your program from the Command Line ?Then a simple solution could be to run you program like this
./test >testfile

The > operator works on Linux. You might have to use a different operator for your system

No, the file doesn't produce any output.

void main() is incorrect
scanf("%s", &array); is incorrect.

Mr Walt asked via 'bad reputation'

# WHY is it incorrect? - WaltP

Since he did not follow with a decent post to explain his negative action and only because that might cast some doubt of my words on those that do not know better, I'll explain this.
If you do not know WHY, it is for you to find out WHY. You can take it or leave it. You can ask for more if you're serious about it.

Edited 6 Years Ago by Aia: n/a

My point was
1) it works -- therefore it doesn't seem wrong
2) the OP has no idea if you are right nor if they should even listen to one of us.

IMO, if you say something intuitively in error, at least give an explanation of some sort. We are contradicting what they've been taught, and they have no idea if we're experts or fools.

Simple solution- don't just say something that's intuitively unclear - point it out by simply adding something like:

And here's why.

Comments
Here's my point. Stop micromanaging. I'll explain what I want to explain. You are not authority in how it must be done, neither.

My point was
1) it works -- therefore it doesn't seem wrong
2) the OP has no idea if you are right nor if they should even listen to one of us.

IMO, if you say something intuitively in error, at least give an explanation of some sort. We are contradicting what they've been taught, and they have no idea if we're experts or fools.

Simple solution- don't just say something that's intuitively unclear - point it out by simply adding something like:

And here's why.

Mister, last time I checked there was not authoritative rule that dictates how a reply to help must conform with. Nor every respond to point errors must warrant an explanation. And even if it did it should be up to the grace of the poster (and it is) to decide what to give.
Sometimes all that you have grace for is to point some errors. Depending of motivation, how many posts you have helped with, already, and the judgment of efforts in the part of the OP, that you write more specific or less.

You gave some "points" for your action after the fact. I'll give you something to consider for next time. You are always welcome to add your extra two cents worth of opinion. You can even point to misleading opinions if you feel truth is in your side (very dangerous). However, expecting YOUR way to be THE WAY, can show only the JERK's way.

Edited 6 Years Ago by Aia: n/a

This article has been dead for over six months. Start a new discussion instead.