Alrighty. So this is what I came up with. I haven't tried compiling it yet, because i'm still sketchy on writing it back to the file, so I wanted to pass it by you guys for inspection before I bothered. Again, any help is always appreciated!
Code:
void handle_file( int modifier, int max_allowed, int add_to )
{
int x, par;
for ( x = 0; x < loot_count; x++ )
{
if ( ( modifier + add_to ) < max_allowed )
{
if ( modifier > max_allowed )
{
modifier = max_allowed;
}else{
modifier + add_to;
}
}
}
return modifier;
}
int main ( void )
{
int max_allowed, add_to, x, modifier;
char filename[50];
char buf[1000];
char * ptr;
printf("Enter the filename to be used.\n");
scanf( "%s", filename );
printf("Enter the max allowed loot result.\n");
scanf( "%d", &max_allowed );
printf("Enter the number to add to the loot.\n");
scanf( "5d", &add_to );
printf("Processing...\n");
FILE * fp;
if ( fp = fopen( filename, "r" ) = NULL )
{
printf("Invalid file name.\n");
exit(1);
}
while( fgets( buf, BUFSIZ, fp ) )
{
if( ( ptr = strchr( buf, ' ' ) ) && *( ptr + 1 ) )
{
ptr++;
fscanf( buf, "%d" &modifier );
handle_file( modifier, max_allowed, add_to );
fprintf( buf, "%d", &modifier );
}else{
printf("Completed.\n");
exit(1);
}
}
return 0;
}