Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!samsung!sdd.hp.com!ucsd!nosc!crash!pnet01!lkoop From: lkoop@pnet01.cts.com (Lamonte Koop) Newsgroups: comp.sys.amiga.programmer Subject: Re: Problems with string handling... Message-ID: <7617@crash.cts.com> Date: 18 Feb 91 05:16:36 GMT Sender: root@crash.cts.com Organization: People-Net [pnet01], El Cajon CA Lines: 53 gt1619a@prism.gatech.EDU (Net Runner Mark V) writes: >I have been having a problem in writing a file parser (which reads in a file >which contains a database of information and separates and translates the info >into data files for another suite of programs). > >Problem: system crashes when I do this. It gets as far as the string copy, >but falls apart at the string concatenation . I'm using Manx. > >The code: >- . - >- . - >char type[2], *seqName, *tblName, *string; >- . - >fscanf(input," %s;",string); >strcpy(seqName,string); >strcat(seqName,".seq"); Ok, but first thing....have you allocated memory for the pointers you declared above? As this code is right now (assuming no other declarations), *seqName, *tblName, and *string are NULL. In fact, I'm surprised your code doesn't have problems at the fscanf() function, as this will put the scanned input to whatever *string points at (location 0). This should work, if this is the case: char type[2], seqName[50], tblName[25], string[100]; fscanf(input," %s'",string); strcpy(seqName,string); strcat(seqName,".seq"); Note that I have used arbitrary array size declarations. If you want to have better control on the size of the char arrays, then simply declare them as you did, using malloc() to get a chunk of memory of a size suitable for your need for each pointer. >------------------------------------------------------------------------- >James D. McIninch >------------------------------------------------------------------------- >School of Applied Biology >Georgia Institute of Technology, Box 31619 >Atlanta, Georgia 30332 >uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt1619a >Internet: gt1619a@prism.gatech.edu >************************************************************************** >* The goal: to design CAD/CAM software and hardware for the creation * >* of living things... * >************************************************************************** LaMonte Koop Internet: lkoop@pnet01.cts.com ARPA: crash!pnet01!lkoop@nosc.mil UUCP: {hplabs!hp-sdd ucsd nosc}!crash!pnet01!lkoop "Yes, I am their leader...now tell me where they went!"