CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

chained list with fprintf output

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Richter



Joined: 18 Mar 2005
Posts: 8

View user's profile Send private message

chained list with fprintf output
PostPosted: Thu Apr 28, 2005 6:19 am     Reply with quote

Hi guys, I m using the PIC 18f6720 ICD U40 and using the old version 3.180 of PCB PCM and PCH
and try to get this litle code to work.
My output via Tera Term Pro is everytime very strange and sometimes changes. When I try to change the value via pointer more strange things happen!! Via pointer the new value is ok and everything is fine. But when I change the value direkt in the structure nothing happens!!! What s wrong?

Here is the Code

Code:

#include <18F6720.h>

#DEVICE ICD=TRUE          // delete line #device ICD=TRUE to get a standalone application + see fuses !!
#DEVICE ADC=10
#pragma USE DYNAMIC_MEMORY    // For using malloc or any other dynamic memory functions.

#include "pins.h"

#use delay(clock=20000000) // oscilator = 20 Mhz
#use rs232 (baud=115200, xmit=Pin_TX1, rcv=Pin_RX1, STREAM=COM2) // external comunication
#use rs232 (baud=115200, xmit=Pin_TX2, rcv=Pin_RX2, STREAM=COM1) // internal comunication Pic2Pic

#fuses HS,NOWDT,WDT1,STVREN,DEBUG    //Fuses: HS = High speed osc( > 4mhz), NOWDT = No watchdog timer, WDT1 = WDT uses 1:1 Postscale
                                     //!! NODEBUG should be inserted for standalone application !!

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



struct List_Element
{
long int value;
struct List_Element* next;
};

typedef struct List_Element List_Elem;


void main (void)
{
long int i;
List_Elem *head = NULL;

List_Elem first;
first.value=10;
first.next = NULL;
head = first;
(*head).value = i;

fprintf(COM2,"\r\n%8ld",i);

}


When I use fprintf with the argument first.value it s all fine but with pointer its not!!!
Please CCS and folks spam my Code! Exclamation
_________________
Why I get all these strange problems ?
Ttelmah
Guest







PostPosted: Thu Apr 28, 2005 8:15 am     Reply with quote

Try with:
head = &first;

as posted, CCS will put the contents of first into 'head', rather than the address. It is worth not 'assuming', that an element name will automatically translate to an address, since CCS while accepting this for an array, does not do this for a structure...

Best Wishes
Richter



Joined: 18 Mar 2005
Posts: 8

View user's profile Send private message

RIGHT!
PostPosted: Fri Apr 29, 2005 12:32 am     Reply with quote

DAMN!! OF COURSE .... that s embarassing!!!

Sometimes u can t see the simplest errors in the code!!!
THNX A LOT!!!!! Embarassed Embarassed Embarassed
Shame On Me
_________________
Why I get all these strange problems ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group