illIAm 0 Newbie Poster

Ah, 30 minutes - that explains all
http://cboard.cprogramming.com/c-programming/138916-copying-into-array-display-command-promt.html

http://www.catb.org/~esr/faqs/smart-questions.html#urgent

lol
so you sent me a link to read how to ask for help? So what bit of there was I unpolite or whatever .... and yeh i did read it and yeh i got it fixed

IF i was asking for help from scratch with no code id understand you guys being off handish a simple ... hey look at line so and so ... thats all i needed

anywho ... best not to ask help from other IT guys ... and i cant really point fingers at u guys only even the people i study with are the same

illIAm 0 Newbie Poster

Hey narue
could you please just tell me exactly what to do where
because i have this assignment due in 30 mins. If i had more time I would have worked it out

illIAm 0 Newbie Poster
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
int main() 
{
    char *fname,*str,ch,cityname[5][12];
    int monthnum,rainfall,pos,monthvalues[5][6],flag,i,j,cpos,npos=0,count=0;
    FILE *fp;							//File Pointer

    fp=fopen("CityRain.txt","r+");
	if(fp==NULL)
	{
		printf("Cannot input file\n");
		getch();
		return 0;
	}
    for(i=0;i<5;i++)    
        strcpy(cityname[i],"");
        
    for(i=0;i<5;i++)       
     for(j=0;j<6;j++)        
        monthvalues[i][j]=0;
        
   	while(!feof(fp))
	{	     	     
        pos=0;
        flag=1;
         str = (char* ) malloc(12 * sizeof(char) );		//dynamic memory allocation
        while(flag)
        {
             fscanf(fp,"%c",&ch);
           //  ch=fgetc(fp);
 	          if(ch==',')
              {
                 flag=0;   
              }
              else
              {                         
 	              str[pos]=ch;
 	              pos++;
              } 	       
        }	    
 	  
 	    cpos=-1;
 	    for(i=0;i<5;i++)  
        {  
           if(strcmp(str,cityname[i])==0)
               cpos=i;
         
        }
        if(cpos==-1)
        {             
              
              strcpy(cityname[npos],str);
                
                npos++;
         }
  
	     fscanf(fp,"%d",&monthnum);
	    
 	     fscanf(fp,"%c",&ch);
 	     fscanf(fp,"%d",&rainfall);
 	  
 	    if(npos==1 || npos==2)
 	         monthvalues[1][monthnum-1]=rainfall;
        else
             monthvalues[npos-1][monthnum-1]=rainfall;
 	     count++;
   
     }
     printf("City              Jan      Feb    Mar    Apr    May    Jun\n\0");
      for(i=1;i<5;i++)  
      {               
             printf("%s\t\0",cityname[i]);
             if(i!=2)printf("\t\0");
            for(j=0;j<6;j++)
                  printf("%d\t\0",monthvalues[i][j]);
             printf("\n\0");
      }
     getch();
     return 0;
}

See i have added the'\0' still dosent change

illIAm 0 Newbie Poster

also the output file is supposed to have just one city name and its stats horizontally next to it ... i don't know where I went wrong because its putting these other city names too

illIAm 0 Newbie Poster

ermm ok ... where do i put that '\0' because the code is working right now i do not want to go and mess it up

illIAm 0 Newbie Poster

Hi i got this progamm working fine
it is supposed to read a comma delimited text file store as an array and the output a formatted version
The problem is its outputting something really weird I dont know why.

The text file it is supposed to read

Darwin,3,33
Darwin,1,11
Darwin,6,66
Darwin,4,44
Darwin,5,55
Brisbane,2,222
Brisbane,1,111
Brisbane,6,666
Brisbane,3,333
Sydney,1,101
Sydney,2,202
Sydney,3,303
Sydney,6,606
Sydney,5,505
Sydney,4,404
Perth,3,313
Perth,4,414
Perth,5,515

THE CODE

#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
int main() 
{
    char *fname,*str,ch,cityname[5][12];
    int monthnum,rainfall,pos,monthvalues[5][6],flag,i,j,cpos,npos=0,count=0;
    FILE *fp;							//File Pointer

    fp=fopen("CityRain.txt","r+");
	if(fp==NULL)
	{
		printf("Cannot input file\n");
		getch();
		return 0;
	}
    for(i=0;i<5;i++)    
        strcpy(cityname[i],"");
        
    for(i=0;i<5;i++)       
     for(j=0;j<6;j++)        
        monthvalues[i][j]=0;
        
   	while(!feof(fp))
	{	     	     
        pos=0;
        flag=1;
         str = (char* ) malloc(12 * sizeof(char) );		//dynamic memory allocation
        while(flag)
        {
             fscanf(fp,"%c",&ch);
           //  ch=fgetc(fp);
 	          if(ch==',')
              {
                 flag=0;   
              }
              else
              {                         
 	              str[pos]=ch;
 	              pos++;
              } 	       
        }	    
 	  
 	    cpos=-1;
 	    for(i=0;i<5;i++)  
        {  
           if(strcmp(str,cityname[i])==0)
               cpos=i;
         
        }
        if(cpos==-1)
        {             
              
              strcpy(cityname[npos],str);
                
                npos++;
         }
  
	     fscanf(fp,"%d",&monthnum);
	    
 	     fscanf(fp,"%c",&ch);
 	     fscanf(fp,"%d",&rainfall);
 	  
 	    if(npos==1 || npos==2)
 	         monthvalues[1][monthnum-1]=rainfall;
        else
             monthvalues[npos-1][monthnum-1]=rainfall;
 	     count++;
   
     }
     printf("City              Jan      Feb    Mar    Apr    Jun\n");
      for(i=1;i<5;i++)  
      {               
             printf("%s\t",cityname[i]);
             if(i!=2)printf("\t");
            for(j=0;j<6;j++)
                  printf("%d\t",monthvalues[i][j]);
             printf("\n");
      }
     getch();
     return 0;
}

Am supposed to get a better looking output
But this is what I get
OUTPUT

City              Jan      Feb    Mar    Apr    Jun

Darwin═════
Brisbane═══
Sydney═════
Perth══════
Perth═════,
Perth══════²²²²½½½½½½½½         11      0       33      44      55      66


Brisbane═══
Sydney═════
Perth══════
Perth═════,
Perth══════²²²²½½½½½½½½ 111     222     333     0       0       666

Sydney═════
Perth══════
Perth═════,
Perth══════²²²²½½½½½½½½         101     202     303     404     505     606


Perth══════
Perth═════,
Perth══════²²²²½½½½½½½½         0       0       313     0       0       0

Please tell me where I am wrong, because am …

illIAm 0 Newbie Poster

hey its me again
i dont know whats the issue it just wont work
am using visual studio as the compiler

I will just post the entire code up
see what u guys think

#include <stdio.h>
#include <stdlib.h>

void main()

{
	int emp_id;
	float hours;
	float mon, tue, wed, thur, fri;
	float norm_pay, over1_pay, over2_pay, over_pay;
	char dep_code;
	char choice;

	
	printf("Do you want to enter any more employee details (Y/N): ")
	scanf("%c%*c", &choice);

	do
	{

	printf("Enter employee Id: ");
	scanf("%d%*c", &emp_id);

	printf (" Please enter the hours worked for each day in the week when promted to \n");

	do
	{
		printf ("Please enter the hours worked on Monday: ");
		scanf ("%f.2%*c",&mon);
		if (mon > 12)
		{
			printf("\n Invalid hours were entered, the hours should not exceed 12 hours");
			printf("\n Please enter the hours worked on Monday:");
			scanf ("%f.2%*c",&mon);
		}
		else
			break;
	} while (mon !> 12);

	do
	{
		printf ("Please enter the hours worked on Tuesday: ");
		scanf ("%f.2%*c",&tue);
		if (tue > 12)
		{
			printf("\n Invalid hours were entered, the hours should not exceed 12 hours");
			printf("\n Please enter the hours worked on Tuesday:");
			scanf ("%f.2%*c",&tue);
		}
		else
			break;
	} while (tue !> 12);

	do
	{
		printf ("Please enter the hours worked on Wednesday: ");
		scanf ("%f.2%*c",&wed);
		if (wed > 12)
		{
			printf("\n Invalid hours were entered, the hours should not exceed 12 hours");
			printf("\n Please enter the hours worked on Wednesday:");
			scanf ("%f.2%*c",&wed);
		}
		else
			break;
	} while (wed !> 12);

	do
	{
		printf …
illIAm 0 Newbie Poster

hey Kunal thanks for that - didnt think of a do ... while loop

but the requirement of the program is to ask if i want to add new employee after every entry - with the solution u just gave me - it just keeps asking for the employee code over and over again - dosent exit at any point

illIAm 0 Newbie Poster

i cant understand what you r actually trying to do..
can you post your whole code here?

// This programe is going to be used to calculate the payroll of employees in a comapany//


# include <stdio.h>
# include <stdlib.h>

void main()

{
	
	char choice, N, Y;
	int emp_id;
    
	printf ("Would you like to enter in any more employees: ");
	scanf ("%c%*c", &choice, &Y, &N);
    while ( choice != N && choice == Y)
	{ 
	

	printf ("please enter employee number: ");
	scanf ("%d%*c", &emp_id);
	
	}
	
	
	system("pause");










}

I have taken out the rest of the working within the while loop
just left the emp id bit for an example

illIAm 0 Newbie Poster

done
I did do the scanf bit forgot to include it here
then I was including the Y and N as 'Y' and 'N'
changed that and the == bit - now it just dosent compile saying some kind of fatal error
lol

illIAm 0 Newbie Poster

Hi
have done the whole program but now am stuck at what initially seemed like a simple thing a repitation loop
the program is supposed to ask the user if he/ she wants to continue with adding more data - if no exit and continue with the other stuff.

char choice, y, Y, n,  N;

while (choice != N && choice = Y)
{code 
code
code
)

now it keeps coming up with 3 different errors
1 it either just crashes
2 it just keeps doing the stuff of the while loop
3 it keeps telling me choice hasnt been initalized

I have just put in the bits thats causing a problem the rest of the program is fine