Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- c program dumping core on unix
- #include<stdio.h>
- #include<stdlib.h>
- void main()
- {
- char *name;
- name="James Bond";
- int i=0;
- sprintf(name,"%s/%d",name,i);
- printf("String is %s",name);
- }
- #include <stdio.h>
- int main (void) {
- char *name;
- char name2[100]; // make sure plenty of space.
- name = "James Bond";
- int i = 0;
- sprintf (name2, "%s/%d", name, i);
- printf ("String is %sn", name2);
- return 0;
- }
- name = "Bob";
- *name = 'J'; // to try and make "Job"
- char *path = "/tmp/";
- char *file = "xyz.txt"
- char fullpath = malloc (strlen (path) + strlen (file) + 1);
- if (fullpath == NULL)
- // error and exit condition
- strcpy (fullpath, path);
- strcat (fullpath, file);
- // use fullpath for your nefarious purposes :-)
- free (fullpath);
- char name[]="James Bond";
- #include<stdio.h>
- #include<stdlib.h>
- void main()
- {
- char name[] = "James Bond";
- int i = 0;
- printf("String is %s/%d", name,i);
- }
- char *name;
- name="James Bond"; // name is pointing into read-only memory
- int i=0;
- sprintf(name,"%s/%d",name,i); // trying to write to read-only memory
- printf("String is %s",name);
- char name[32] = "James Bond";
- ...
- char* str = NULL; // pointer should be initialized to NULL
- asprintf (&str, "someformat %d", 20);
Add Comment
Please, Sign In to add comment