|
|
View previous topic :: View next topic |
Author |
Message |
Richter
Joined: 18 Mar 2005 Posts: 8
|
chained list with fprintf output |
Posted: Thu Apr 28, 2005 6:19 am |
|
|
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! _________________ Why I get all these strange problems ? |
|
|
Ttelmah Guest
|
|
Posted: Thu Apr 28, 2005 8:15 am |
|
|
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
|
RIGHT! |
Posted: Fri Apr 29, 2005 12:32 am |
|
|
DAMN!! OF COURSE .... that s embarassing!!!
Sometimes u can t see the simplest errors in the code!!!
THNX A LOT!!!!!
Shame On Me _________________ Why I get all these strange problems ? |
|
|
|
|
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
|