I am writing a code that needs to open a file, create an output file, run through my function, prints the results to the output file, and closes them within a loop. Here is my code: - #include <stdlib.h>
-
#include <stdio.h>
-
#include <math.h>
-
#include <string.h>
-
-
#include "util.h"
-
-
//Main Loop
-
int main()
-
{
-
-
int i, flag;
-
int num_files;
-
int len_str;
-
char *idir = "/home/smurphy/data/20060117/";
-
char **file_names;
-
char *fullfn;
-
char *output;
-
-
//Define variables needed from the metar data:
-
char station[5]; //Station identifier
-
char weather[3];
-
-
int snow_value;
-
-
/* Get list of files to be processed. */
-
flag = get_dir_list(idir, &num_files, &file_names);
-
-
for(i=0; i<num_files; ++i){
-
-
printf("file name #%d = %s\n", i, file_names[i]);
-
len_str = strlen(idir) + strlen(file_names[i]) + 1;
-
fullfn = calloc(len_str, sizeof(char));
-
-
strcat(fullfn, idir);
-
strcat(fullfn, file_names[i]);
-
printf("fullfn = %s\n", fullfn);
-
-
sprintf(output, "output%d.dat", i);
-
-
FILE *input_stream;
-
FILE *output_stream;
-
-
output_stream = fopen(output, "w");
-
-
if (output == NULL){
-
printf("I could not open your output file.\n");
-
}
-
-
//Opens input file
-
input_stream = fopen(fullfn,"r");
-
-
-
//Loop reads in input file and detemines at which stations snow is occuring at.
-
-
while(fscanf(fullfn, "%s\t%s\n", station, weather) >= 1){
-
-
if (strcmp(weather, "S") == 0){
-
snow_value = 2;
-
fprintf(output, "Stat: %s SigWx: %s SnoVal: %i\n", station, weather, snow_value);
-
}
-
else if (strcmp(weather, "S-") == 0){
-
snow_value = 1;
-
fprintf(output, "Stat: %s SigWx: %s SnoVal: %i\n", station, weather, snow_value);
-
}
-
-
else if (strcmp(weather, "+S") == 0){
-
snow_value = 3;
-
fprintf(output, "Stat: %s SigWx: %s SnoVal: %i\n", station, weather, snow_value);
-
}
-
-
else{
-
snow_value = 0;
-
fprintf(output, "Stat: %s SigWx: None SnoVal: %i\n", station, snow_value);
-
}
-
}
-
-
//Closes files
-
//fclose(fullfn);
-
//fclose(output);
-
-
free(fullfn);
-
free (output);
-
}
-
-
}
-
I am getting incompatible pointer types for arg 1 for my fscanf, fprintf. Can anyone help me out? I have never worked with opening/closing files within a loop, any suggestions?
3 4633
This program worked in college where was made. Check how it is
:: Code removed per FAQ::
MWZ
This program worked in college where was made. Check how it is
:: Code removed per FAQ::
MWZ
mweitz-
Please read our Posting Guidelines and abide by them. We ask that you not 1) post complete code or 2) give out code.
The OP has posted code, and it will help them more to show them where their program is not working, as they understand that better than what was posted, and they will learn more by fixing it.
Well, this looks like homework but I am in a good mood.
The errors you were getting:
a.c:56: warning: passing arg 1 of `fscanf' from incompatible pointer type
a.c:60: warning: passing arg 1 of `fprintf' from incompatible pointer type
a.c:64: warning: passing arg 1 of `fprintf' from incompatible pointer type
a.c:69: warning: passing arg 1 of `fprintf' from incompatible pointer type
a.c:74: warning: passing arg 1 of `fprintf' from incompatible pointer type
I will give you a hint:
You declared fullfn and output as char *fullfn; char *output;
notice in your errors above the function that is being complained about...fscanf and fprintf. Hmmm...what does the "f" in fscanf and fprintf represent...Perhaps fullfn and output should be a different type of variable.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sure |
last post by:
I my php script I call a perl script that perl script will create a log file
From the php script I want to read the log file and write the
output to the browser. This operation has to carried out...
|
by: Danny Anderson |
last post by:
Hola, C++ folk!
I want to have a do...while loop that works with a different file each
iteration, prompting the user for the file name to open and write.
The problem I am having is that the...
|
by: Andrew |
last post by:
I'm adding this as it to me a while to figure out all the pieces to be
able to do this without using Microsoft.Office.Interop which caused me
problems on the web-server.
Streaming is the easy...
|
by: js |
last post by:
Hello, list.
I have a list of sentence in text files that I use to filter-out some data.
I managed the list so badly that now it's become literally a mess.
Let's say the list has a sentence...
|
by: Umesh |
last post by:
/*program to search a* in a text file & write output in a file.*
indicated any character*/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
FILE *f,*fp;
f=fopen("c:/1.txt","r");...
|
by: webinfinite |
last post by:
I am starting a new thread for this topic since previous problem has
been solved.
I have code like this:
#include <stdio.h>
int main(){
|
by: sunnyluthra1 |
last post by:
Hi Everyone,
I am working on a piece of code, that displays the properties(Name, Datatype, size & Description) of the table in the database.
Now I want to further Enhance the code.
I Have created...
|
by: Filemaxor |
last post by:
I have gotten my code to be able to allow people to add new text to a .txt document and able to call up files so the user can see whats in it. The problem i'm having is getting the for loop to work...
|
by: rparimi |
last post by:
I am trying to redirect stderr of a process to a temporary file and
then read back the contents of the file, all in the same python
script. As a simple exercise, I launched /bin/ls but this doesn't...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |