JFK, here is the working code. It compiled perfectly:
Code:
#include <stdio.h>
void drawline(int length, char character);
int main(int argc, char *argv[])
{
FILE *fp;
char *valid, line[20];
int sun=0, rain=0, month=1;
fp = fopen(argv[1], "r");
if (fp == NULL)
{
printf("Put txt file in exe dir\n");
return 0;
}
valid = fgets(line, sizeof(line), fp);
while (valid != NULL)
{
sscanf(line, "%d %d", &sun, &rain);
printf("Month %d:\n", month);
drawline(sun, '*');
drawline(rain, '!');
month++;
valid = fgets(line, sizeof(line), fp);
}
return 0;
}
void drawline(int length, char character)
{
int i=0;
while (i < length)
{
printf("%c", character);
i++;
}
printf("\n");
}
Okay, a couple of changes I made. Instead of the program choosing the file, I just used *arcv[] and retreived the file from that. So, to run the program, you would do:
C:\Program Files:>Weather.exe <txt file here>
Understand?
--Garfield