Skip to main content

Thread: printing alphabet with malloc realloce


code:
#include "stdafx.h" #include <stdlib.h> #include <stdio.h>   int _tmain(int argc, _tchar* argv[]) { int i; char *pa;    pa[0]='a';   for(i=1;i<26;i++){     pa= (char *) realloc (pa, i+1 * sizeof(char));   pa[i]='a'+i;            } printf("%s",pa);          }
really whats problem

you don't allocate memory pa point in first place.


code:
char *pa ;
will allocate space pointer - subsequently pointing anywhere

need call malloc allocate memory segment p - before

code:
pa[0] = "a" ;
in short should :
code:
char *pa;  pa= (char *) malloc (1 * sizeof(char));  pa[0] = 'a' ;


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk printing alphabet with malloc realloce


Ubuntu

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support