Thread: problems with structure

  1. #76
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    Code:
    if(VPD < 0.5)
    			{
    				 set = strcpy(store, 1);
    				 printf("value is %s",set);
    
                           }
    			else
    			{	 set1 = strcpy(store1,0);
    				printf("val is %s",set1);
                          }
    is this the way to use strcpy for integer?or how can we do this?i need to copy the integer to a variable and need to use it later.

  2. #77
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by pokhara View Post
    is this the way to use strcpy for integer?or how can we do this?i need to copy the integer to a variable and need to use it later.
    You don't need to use strcpy() with ints, you just use "set=1" -- or do you mean you want a number in a string? Why?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #78
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    Code:
                   if(VPD < 0.5)
    			{
                    printf("value is %d ",1);
    			}
                  else
    
    			{
    
                     printf("val is %d ",0);
    			}
    i did this..i know this is the way to do..i have to use this variable value and val in the next step..like i need to add all the 1 and use the sum as a output...

  4. #79
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    hello MK27..do u have yahoo id..so we can chat on yahoo..coz it is my work at office and i don't want this to get displayed...would u mind doing this?or can't we have private forum also

  5. #80
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I'm not sure if I understand you, but if you want to add one to an int variable, just use:

    x++;

    or

    x += 1;
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #81
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    how can i add the number of 1's ..like i need to count the number of 1 and store it an another variable.

  7. #82
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by pokhara View Post
    how can i add the number of 1's ..like i need to count the number of 1 and store it an another variable.
    If you can do
    Code:
    val = ((7.5 * DewPointC) / (237.7 + DewPointC));
    surely you can do
    Code:
    count = count + 1;
    ?

  8. #83
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    i tried to calculate the following formula but it is not taking the -ve sign due to which it is giving the wrong value.
    Code:
    
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    
    void read();
    
    
    int Time, RH, retv;
    float DewPointC;
    float DryTempC;
    float val, val1;
    float VPD,vapourp, setvapp; 
    char line[256];
    FILE *in;
    int main()
     {	
    	in = fopen("KBIS_2005.txt", "r");
    	read();	
    	
    	return 0;
    	
    			
    	
    }
    
    void read()
    {	
    	
    	int i;
    	char store, store1;
    	char * set, * set1;
    	printf("VDP\n");
    	for(i = 0; i<=240; i++) 
    		{
    			fgets(line,256,in);
       
    retv=sscanf(line,"%d %f %f %d\n",&Time,&DewPointC,&DryTempC,&RH);
    			if (!retv) continue;
    
    
    val = ((7.5 * DewPointC) / (237.7 + DewPointC));
    			
    			vapourp = pow(611,(7.5 * DewPointC) / (237.7 + DewPointC));
    			printf("the vapourp is :%f",vapourp);
    		setvapp = pow(611, (7.5 * DryTempC)/(237.7 + DryTempC));
    			printf("the setvapp is :%f",setvapp);
    	
    		
    			VPD = setvapp - vapourp;
    printf("VPD IS %f",VPD);
    
    			if(VPD < 0.5)
    			{
    				 printf("value is %d\n",1);
    			}
    			else
    			{	 
    				 printf("value is %d ",0);
    			}
    					
    			
    		}	
    			
    			
    	
    }
    here in this code, the value must be 0 for the first reading but since it is giving in -ve sign, it is giving 1 as a result which is wrong. i know the formula is correct. how to make sure that it reads the -ve sign too.

  9. #84
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    hello MK27...I have posted my problem..please do help me

  10. #85
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Print out the variables as you read them in: is the negative sign there? (It doesn't sound like you have an error; if VPD is negative, aren't you supposed to get 1 as a result?)

  11. #86
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    yah but i need to get the 0 too and the number of 1 should be 111...but m getting all 240 number of 1's. and i checked using taking the value individually and it is giving 0. but while reading the whole file it is giving 1.
    Code:
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    
    
    int main()
    {
    
    int Time = 0, RH = 67;
    float DewPointC = -5;
    float DryTempC = 0.6;
    float val, val1;
    float VPD,vapourp, setvapp; 
    char line[256];
    
    vapourp = pow(611,(7.5 * DewPointC) / (237.7 + DewPointC));
    
    setvapp = pow(611, (7.5 * DryTempC)/(237.7 + DryTempC));
    
    VPD = setvapp - vapourp;
    
    printf("VPD IS %f",VPD);
    
    			if(VPD < 0.5)
    			{
    				 
    				 printf("value is %d\n",1);
    			}
    			else
    			{	
    				 printf("value is %d ",0);
    			}
    }

  12. #87
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by pokhara View Post
    hello MK27...I have posted my problem..please do help me
    I'm not much for math so I can't follow this very well, but here's a few points:

    • you may want to use powf() and not pow() with floats
    • remember to link the math library (-lm) in addition to using #include
    • make sure you use "f" after floating point numbers (eg, "237.7f" not just "237.7" so they do not end up rounded into ints, esp. if using pow and not powf...


    Does this line:
    Code:
    printf("VPD IS %f",VPD);
    yield the correct value?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  13. #88
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by pokhara View Post
    yah but i need to get the 0 too and the number of 1 should be 111...but m getting all 240 number of 1's. and i checked using taking the value individually and it is giving 0. but while reading the whole file it is giving 1.
    Code:
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    
    
    int main()
    {
    
    int Time = 0, RH = 67;
    float DewPointC = -5;
    float DryTempC = 0.6;
    float val, val1;
    float VPD,vapourp, setvapp; 
    char line[256];
    
    vapourp = pow(611,(7.5 * DewPointC) / (237.7 + DewPointC));
    
    setvapp = pow(611, (7.5 * DryTempC)/(237.7 + DryTempC));
    
    VPD = setvapp - vapourp;
    
    printf("VPD IS %f",VPD);
    
    			if(VPD < 0.5)
    			{
    				 
    				 printf("value is %d\n",1);
    			}
    			else
    			{	
    				 printf("value is %d ",0);
    			}
    }
    Is your output going to a file, or are you only looking at the last forty lines of output in your terminal window?

  14. #89
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    what are the compiling and running command for c sharp program? I wrote a c sharp program and for compilation i used mcs filename.cs. But for running, I don't know the command. So please help me.

  15. #90
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Another case of bumping a thread.
    Post it in the C# forum.
    << !! Posting Code? Read this First !! >>
    Spidey out!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing structure arrays to functions?
    By bem82 in forum C Programming
    Replies: 3
    Last Post: 10-30-2006, 06:17 AM
  2. structure ...solution plz????
    By hegdeshashi in forum C Programming
    Replies: 4
    Last Post: 07-24-2006, 09:57 AM
  3. structure problems in windows program.
    By Bajanine in forum Windows Programming
    Replies: 3
    Last Post: 04-19-2004, 06:18 PM
  4. Realloc problems with sturcture array inside structure
    By daveyand in forum C Programming
    Replies: 2
    Last Post: 03-29-2004, 06:48 AM
  5. Structure problems...
    By MillaTime in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2002, 09:27 PM