| | |
*strcpy and linked list
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
Hey!
I'm looking for some help on what I'm doing wrong as I'm new to C#. I'd really like it if you can explain why my code isn't working and then offer some help on how to fix it without "making it easy" for me ;o) I have to understand what's happening :oP hehe...
On to the problem:
I have a linked list containing pointers to lines read from a file. What I would like to do is copy these lines into a char.
Can I use *strcpy for this? The way I use *strcpy now isn't working; I'm not getting the entire text copied. Maybe the error isn't the strcpy but some other part of my code?
Here's the code I guess is relevant:
All help is appreciated! :o)
I'm looking for some help on what I'm doing wrong as I'm new to C#. I'd really like it if you can explain why my code isn't working and then offer some help on how to fix it without "making it easy" for me ;o) I have to understand what's happening :oP hehe...
On to the problem:
I have a linked list containing pointers to lines read from a file. What I would like to do is copy these lines into a char.
Can I use *strcpy for this? The way I use *strcpy now isn't working; I'm not getting the entire text copied. Maybe the error isn't the strcpy but some other part of my code?
Here's the code I guess is relevant:
C# Syntax (Toggle Plain Text)
struct lenket{ struct lenket *neste; char *dir; }; struct lenket *liste = NULL, *siste = NULL, *pdp, *q;
C# Syntax (Toggle Plain Text)
int main(int argc, char **argv) { FILE *fp; char *everything; unsigned int filesize; char *p1, *p2; char *filnavn = argv[2]; if ((fp = fopen(filnavn,"r")) != NULL) { printf("Filen %s er åpnet.\n\n", filnavn); fseek(fp, 0, SEEK_END); filesize = ftell(fp); p1=p2 = everything = malloc(sizeof(char) * filesize); fseek(fp, 0, SEEK_SET); fread(everything, 1, filesize+1, fp); everything[filesize] = 0; while(p1-everything < filesize){ if(*p1 =='\n'|| p1-everything == filesize-1 ){ if(*p1==0){ break; } *p1='\0'; pdp=malloc(sizeof(struct lenket)); pdp->neste=NULL; pdp->dir=malloc(p1-p2+1); strncpy(pdp->dir, p2, p1-p2); if(liste==NULL){ liste=siste=pdp; }else{ siste->neste=pdp; siste=pdp; } p2=p1+1; }else{ ++p1; } } pdp=liste;
C# Syntax (Toggle Plain Text)
char *teksten = NULL; teksten=malloc(sizeof(teksten)+1); do { *strcpy(teksten, pdp->dir); printf("%s\n", pdp->dir); } while((pdp=pdp->neste) != NULL);
All help is appreciated! :o)
Well, the code you just gave is not C#
. It's C/C++...
. It's C/C++... -Ryan Hoffman
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
![]() |
Similar Threads
- Removing an item from head of linked list (C)
- Searching linked list (C)
- Linked list search problems (Computer Science)
- sort linked list help please (C)
- more linked list printing problems (C)
- Cannot figure out how to implement linked list and rbtree for a project! (Java)
- Linked List (C++)
- help by sorting a simply linked list (C)
Other Threads in the C# Forum
- Previous Thread: Compile A Visual C# Project , How?!?!?!
- Next Thread: Wanted source code
| Thread Tools | Search this Thread |
.net access algorithm animation array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom customactiondata database datagrid datagridview dataset datastructure date/time datetime datetimepicker degrees development dll draganddrop drawing encryption enum event excel file filename files form format forms function gdi+ gis gtk hash image index input install java label list listbox mandelbrot math mouseclick mysql operator outlook2003 path photoshop picturebox pixelinversion pixelminversion post programming radians regex remoting richtextbox server sleep snooze socket sql statistics stream string table tables tcp text textbox thread time timer update usercontrol usercontrols validation visualstudio webbrowser webcam wia windows winforms wpf xml





