puts function gives garbage value in C -
i want re-create 1 string string using pointer , getting garbage value (some unknown character) printf function. wrong it? output "string copy**". @ place of ** getting unknown character.
#include <stdio.h> #include <conio.h> void main() { char *s="string copy",*c,*temp;//temp used //pointer on 1st position clrscr(); while(*s!=null) { *c=*s c++; s++; } c='\0'; c=temp;//back pointer first position printf("string c:); puts(c); getch(); }
you need allocate memory char * variables.
also never assign value temp (or allocate space it) later in code assign c = temp. means wherever c @ in memory assigned whatever in memory @ location of temp.
c
No comments:
Post a Comment