Thread: problems with structure

  1. #31
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by MK27 View Post
    Clue:
    Code:
    for(i = 0; i<240; i++) {
    	fgets(line,256,in);
    fixed
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  2. #32
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    ur code is working fine but what is the problem is that i am not getting the exact readings. the last 240 is correct but the upper one is showing different readings. so I am checking it. U just be online please.

  3. #33
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    MK27..now the readings are fine but i used unsigned to display the minus sign too but while doing this i am getting different values after DewPointC. I got correct values for Time and DryPointC but for DewPointC i got all 0 and for RH i am getting some garbage values.

  4. #34
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by pokhara View Post
    i used unsigned to display the minus sign too but while doing this i am getting different values after DewPointC.
    You have it backward. A signed number can have a sign, + or -. An unsigned number can only be positive.
    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

  5. #35
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    i didnot get u. So now how should i change the codes?

  6. #36
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by pokhara View Post
    i didnot get u. So now how should i change the codes?
    Post the codes again...
    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

  7. #37
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main()
     {
    	int Time, RH, retv;
    	signed DewPointC;
    	float DryTempC;
    	char line[256];
    	int i;
    	FILE *in = fopen("KBIS_2005.txt", "r");
    	for(i = 0; i<=240; i++) 
    		{
    			fgets(line,256,in);
    			retv=sscanf(line,"%d %f %f %d",&Time,&DewPointC,&DryTempC,&RH);
    			printf("%d items read: %d %f %f %d\n",retv,Time,DewPointC,DryTempC,RH);
    		}
    
    	return 0;
    }

  8. #38
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Ah. Well, this is not a real datatype:
    Code:
    signed DewPointC;
    Just make it a float!

    That should not compile at all, by the way. What compiler are you using?
    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

  9. #39
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    i used float too but while using it I am not getting the correct readings. Again I will try. I am using gcc compiler at linux.

  10. #40
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main()
     {
    	int Time, RH, retv;
    	float DewPointC;
    	float DryTempC;
    	char line[256];
    	int i;
    	FILE *in = fopen("KBIS_2005.txt", "r");
    	for(i = 1; i<=241; i++) 
    		{
    			
    			fgets(line,256,in);
    			retv=sscanf(line,"%d %f %f %d",&Time,&DewPointC,&DryTempC,&RH);
    			printf("%d items read: %d %f %f %d\n",retv,Time,DewPointC,DryTempC,RH);
    		}
    
    	return 0;
    }
    	
    
    thnks now i am getting the correct readings. but i am getting wrong garbage values at the beginning. so how should i remove it.

  11. #41
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by pokhara View Post
    I am using gcc compiler at linux.
    Hmph. Looks like that does pass gcc, which is what I use too. Anyway, "signed" is a modifier for a datatype, not a datatype of it's own. What specifically is wrong with the data you recieve, if you use float?
    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

  12. #42
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    yah i got it..but i am stil getting the garbage value at the beginning.how to delete those?

  13. #43
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by pokhara View Post
    yah i got it..but i am stil getting the garbage value at the beginning.how to delete those?
    What do you mean by "garbage values"? Show me an example.
    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

  14. #44
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    Code:
    0 items read: 0 0.000000 0.000000 4196133
    4 items read: 0 0.600000 -5.000000 67
    4 items read: 1 0.000000 -3.900000 75
    4 items read: 2 0.000000 -3.900000 75
    i should not be getting the first values. I tried to change the values in the for loop but it is still reading that values.

  15. #45
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by pokhara View Post
    Code:
    0 items read: 0 0.000000 0.000000 4196133
    4 items read: 0 0.600000 -5.000000 67
    4 items read: 1 0.000000 -3.900000 75
    4 items read: 2 0.000000 -3.900000 75
    i should not be getting the first values. I tried to change the values in the for loop but it is still reading that values.
    Is there a "header" line at the top? (If so, you need to skip it.)

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