[EMAIL PROTECTED] wrote:
> Kids are useful for something.
>
> I got my young fresher windows kiddie to apply his (little) knowledge
> of C to your file. We got it compiled, but it keeps throwing
>
> Damn, couldn't open input file!
>
> errors. It can open the input file. It's this bit
>
> /* Make this how long you want the lines to be */
>> #define MAX_LINE_LENGTH 80
>>
>> int main(void)
>> {
>> FILE *fp1;
>> FILE *fp2;
>>
>> char c;
>> char c2;
>>
>> int counter;
>> int endofline;
>>
>> if ((fp1 = fopen("inputfile.txt", "r")) == NULL) {
>> puts("Damn, couldn't open input file!");
>> return -1; }
>
> Can one put $1 and $2 for the files, or something similar?
>
>
> --
>
> With best Regards,
>
>
> Declan Moriarty.
Well, you COULD... ;) With C, though, you have to use argv and argc. :)
Let's change it to do something like what you wanted:
Change the first part to look like this instead:
#include <stdio.h>
#include <ctype.h>
/* Make this how long you want the lines to be */
#define MAX_LINE_LENGTH 80
int main(int argc, char *argv[])
{
FILE *fp1;
FILE *fp2;
char c;
char c2;
int counter;
int endofline;
if (argc != 3)
{
printf("Usage: %s <input filename> <output filename>",
argv[0]);
return -1;
}
if ((fp1 = fopen(argv[1], "r")) == NULL)
{
puts("Damn, couldn't open input file!");
return -1;
}
if ((fp2 = fopen(argv[2], "w")) == NULL)
{
puts("Damn, couldn't open output file!");
return -1;
}
----------------------------
That way, you can specify the input filename and the output filename. ;)
Looks like Declan's gonna be learning himself some C here. :D
Also...
> That's great. I need 90 - yes, about 90. Is that
>
> fputs("\n\t\t\t\t\t\t\t\t\t\t\t\t", fp2);
> fputs("\n\t{11}", fp2);
What I'd recommend there is something similar... The \t are tabs, of
course, and you're just outputting them to the screen... So you're
outputting a newline, 12 tabs, then another newline, and then the string
{11}... I don't think that's what you're intending. :) I'm not quite sure
what you're intending, but "puts" is a VERY simple function... It simply
puts whatever is in there to the output stream (fp2, the second file
pointer, in this case). You're probably looking for something more like
printf, which allows you to output all sorts of stuff in a nicely formatted
manner...
Dave
--
http://linuxfromscratch.org/mailman/listinfo/blfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page