LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-06-2007, 01:09 AM   #1
mei mei
LQ Newbie
 
Registered: Jun 2007
Posts: 2

Rep: Reputation: 0
Wink several question


Hello!
I hope this code is not too long. I am the beginner and modify the code. When I compile it, there are some error messages.
In function 'main';
warning:comparison between pointer and integer

Before I modify the code. I find I would get more than integer and negative value from the data file. ex: 134.56 (in data file) ---> 34.56 (output)
-99.99 (in data file) ---> 99.99 (output)

Could anyone help?
=====================================================
// soilmoisturecode.c :To get the soil moisture data
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#ifndef _LEAPYR
#define LEAPYR(y) (!((y)%400) || (!((y)%4) && ((y)%100)))
#endif

/**********************************************
This is also a comment and is not used by the program
**********************************************/
int Columns[] = {15, 15, 11, 0};
int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main (int argc, char *argv[])
{
/**********************************************************************
Declare variables
**********************************************************************/
FILE *inFile; /* Input file */
FILE *outFile; /* Output file */
char inFilename[100+1]; /* Name of input file */
char outFilename[100+1]; /* Name of output file */
int temp;
int year, month;
char string[11];
char Datestr[11];
char tempstr[201];
char* star="****";
# char yearmonth;

float data[4][31][24][18]= {7777.0};
for (int i=0;i<4;i++){
for (int j=0;j<31;j++){
for (int k=0;k<24;k++){
for (int l=0;l<18;l++){
data[i][j][k][l]= 7777.0;
}
}
}
}
int Table, t, h, col;

/** Check for command-line Options **/
if(argc!=4) {
fprintf(stderr, "%s:<Input File Name> <Year - yy> <Month-mm>\n", argv[0]);
exit(1);
}

/** Assign command-line options to variables **/
strcpy(inFilename, argv[1]);
year = atoi(argv[2]);
month = atoi(argv[3]);
sprintf(Datestr, "%02d%02d", year, month);

/**cloumns checks**/
# char yearmonth = 'year''month'
if( yearmonth < '3012' || yearmonth >= '9912'){
Columns[2]=11;
else{
Columns[2]=15;
}

/**LEAPAR checking **/
if(LEAPYR(year)){
daysinmonth[1]=29;
}
else{
daysinmonth[1]=28;
}
fprintf(stdout, "date = %s\n", Datestr);

/* Open input file */
if (!(inFile = fopen(inFilename, "r")))
{
fprintf(stderr, "Cannot open file: %s\n", inFilename);
exit(0);
}

/* Open output file*/
if (!(outFile = fopen("outFilename.txt", "w")))
{
fprintf(stderr, "Cannot open file: %s\n", outFilename);
exit(0);
}

Table =0;
h =0;
t =0;
/* Start reading the file to identify where the actual data begins by matching the first 10 characters of the line with the start date of the data file. */

while(fgets(string, 5, inFile)) {
fprintf(stdout,"cc1 = %s\n",string);
if (strcmp(string, star) == 0){
Table++;
fgets(tempstr, 200, inFile);
fgets(string, 5, inFile);
fprintf(stdout,"xx1! Table = %s\n", tempstr);
fprintf(stdout,"xx2! Table = %s\n", string);
fprintf(stdout,"xx3! Table = %d\n", Table);
}
fprintf(stdout,"cc2 = %s\n", string);

if(strcmp(string, Datestr) == 0) {
fprintf(stdout,"Data found! Table = %d\n", Table);

char tempd[2];
char temph[2];
int day;
int hour;
fgets(tempd, 3, inFile);
fgets(temph, 3, inFile);
fprintf(stdout,"1Data found! Day = %s\n", tempd);
fprintf(stdout,"1Data found! Hour = %s\n", temph);
day = atoi(tempd);
hour = atoi(temph);

fprintf(stdout,"2Data found! Day = %d\n", day);
fprintf(stdout,"2Data found! Hour = %d\n", hour);

fgets(tempstr, 5, inFile);
fprintf(stdout,"cc15! Table = %s\n", tempstr);

for(col=0; col< Columns[Table-1]; col++) {
fgets(tempd, 3, inFile);
fscanf(inFile,"%f",&data[Table-1][day-1][hour][col]);
if(Table==3){
fprintf(stdout,"cc25! Table = %.2f\n", data[Table-1][day-1][hour][col]);
}

}
if(Table==3)
printf("\n");
fgets(tempstr, 200, inFile);
fprintf(stdout,"cc16! Table = %s\n", tempstr);

if (Table>3)
break;
}else{
fgets(tempstr, 200, inFile);
fprintf(stdout,"cc26! Table = %s\n", tempstr);
}
}

fprintf(stdout,"Start Output!\n");

for(t=0; t<daysinmonth[month-1]; t++){
for(h=0; h<24; h++){
fprintf(outFile, "%02d %02d %02d %02d % .2f % .2f % .2f % .2f % .2f % .2f % .2f % .2f\n",year,month,t+1,h, data[1][t][h][0],data[1][t][h][4],data[1][t][h][8],data[1][t][h][12],data[2][t][h][0],data[2][t][h][4],data[2][t][h][8],data[2][t][h][12]);
}
}
fprintf(stdout,"Finish Output");

return 0;
}
 
Old 06-06-2007, 07:23 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
When the compiler gives you that error message, it also gives you a line number. Would you care to tell us which line of source code triggered the warning? Please don't give us the line number; instead, just post the actual line of code.
 
Old 06-06-2007, 08:07 PM   #3
mei mei
LQ Newbie
 
Registered: Jun 2007
Posts: 2

Original Poster
Rep: Reputation: 0
dear friend. This is my first time to post. About that programming. I would compile it. But the question is I wouldn't get the right output. ftp://ftp.wcc.nrcs.usda.gov/data/sca...036_200110.txt.
 
Old 06-06-2007, 08:15 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by mei mei
dear friend. This is my first time to post. About that programming. I would compile it. But the question is I wouldn't get the right output. ftp://ftp.wcc.nrcs.usda.gov/data/sca...036_200110.txt.
How is that data relevant?????!!!!!!
Are you saying that it compiled successfully but did not give the right results?
Please post something SHORT which describes what it did vs. what it was supposed to do.

Last edited by pixellany; 06-06-2007 at 08:19 PM.
 
Old 06-07-2007, 05:16 AM   #5
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
I've tried to compile the source code that was originally posted. There are grievous (and obvious) syntax errors in it. There's no way it could have run.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Two things: (Probably Simple) Grub question, and a gDesklets question Wilffo Linux - Software 3 05-20-2006 01:33 PM
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM
Lilo/kernel question & font question phek Linux - General 9 09-18-2001 12:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration