home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!bnr.co.uk!uknet!mucs!lucs!scst81
- From: scst81@csc.liv.ac.uk (Mr. I. Rowland)
- Newsgroups: comp.lang.c
- Subject: realloc (again)
- Keywords: Realloc
- Message-ID: <C0pGL7.GqI@compsci.liverpool.ac.uk>
- Date: 11 Jan 93 19:53:30 GMT
- Sender: news@compsci.liverpool.ac.uk (News Eater)
- Organization: Computer Science, Liverpool University
- Lines: 109
- Nntp-Posting-Host: rib.csc.liv.ac.uk
-
- Following my last communication I developed another smaller program that
- uses REALLOC in the same way as my other code:
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define noofstr 5
-
- #define bufsiz 255
-
- void main (void)
-
- {
- char *array; char buff[bufsize];
- int i;
- int bytes ;
-
- for (i=0; i < noofstr; i++)
- {
- printf("Enter string %d : ",i);
- scanf("%255s",buff);
- bytes = strlen(buff)+1;
- array = reilloc(array, (bytes));
-
- if (array== NULL)
- {
- printf("Can't allocate");
- exit(1);
- }
- strcat (array,buff);
- }
-
-
-
- printf(array);
- }
-
-
-
- When this program is run it ask for 5 string inputs which are strung
- together string by string using strcat. However the program seems to
- rather temperamental - sometimes it works sometimes it doesn't. For
- example
-
- Enter string 0 : oiuqrtq
- Enter string 1 : [qoeri
- Enter string 2 : [oqreu
- Enter string 3 : erqui O.K.
- Enter string 4 : [erou
- oiuqrtq[qoeri[oqreuerqui[erou
-
-
- Enter string 0 : asdfgads
- Enter string 1 : asdafadfg
- Enter string 2 : afgadfgadf
- Enter string 3 : adfgadfa
- Enter string 4 : adfgadf
- asdfgads@adfgadf Not produced all of characters
-
-
- Enter string 0 : aasd
- Enter string 1 : adf
- Enter string 2 : asdf O.K.
- Enter string 3 : asdf
- Enter string 4 : asdf
- aasdadfasdfasdfasdf
-
- Enter string 0 : abcdefg
- Enter string 1 : abcdefgh
- Enter string 2 : abcdefghi O.K.
- Enter string 3 : abcdefghij
- Enter string 4 : abcdefghijk
- abcdefgabcdefghabcdefghiabcdefghijabcdefghijk
-
-
- Enter string 0 : adfgadf
- Enter string 1 : adfagdf
- Enter string 2 : adfagdf ?
- Enter string 3 : adfagdfg
- Memory fault(coredump)
-
- Enter string 0 : asdfgh
- Enter string 1 : asdfgh
- Enter string 2 : asdfgh
- Enter string 3 : sdfghjj
- Enter string 4 : asdfghjk
- Memory fault(coredump)
-
- Enter string 0 : a;'dfg
- Enter string 1 : a'ldfg
- Enter string 2 : 'aldfk
- Enter string 3 : 'ladfkf
- Enter string 4 : a'dlfggg
-
- Pid 13488 received a SIGSEGV for stack growth failure.
- Possible causes: insufficient memory or swap space,
- or stack size exceeded maxssiz.
- Memory fault(coredump)
-
-
-
- Is this the fault of the program? Is it the operating system? What can
- to be done to prevent it from happening?
-
- Again this program works on my Atari St using the Lattice C5 compiler.
-
- Ian Rowland (scst81)
- +
-