Professional Documents
Culture Documents
Practical 9 20T28005 Krunal Pandya
Practical 9 20T28005 Krunal Pandya
Practical 9 20T28005 Krunal Pandya
Solution:#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fptr;
char filename[15];
char ch;
Enrollment No.:
b. Write a program to illustrate writing in Files.
Solution:#include <stdio.h>
int main()
{
char ch;
FILE *fpw;
fpw = fopen("C:\\newfile.txt","w");
if(fpw == NULL)
{
printf("Error");
exit(1);
}
return 0;
}
Enrollment No.:
3. C program to create memory for int, char and float variable at run time.
Solution:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *ptr_1;
char *ptr_2;
float *ptr_3;
ptr_1 = (int*)malloc(1*sizeof(int));
ptr_2 = (char*)malloc(1*sizeof(char)*1);
ptr_3 = (float*)malloc(1*sizeof(float));
Enrollment No.:
printf("\nThe value stored in char pointer is : %c",*ptr_2);
printf("\nThe value stored in float pointer is : %f",*ptr_3);
free(ptr_1);
free(ptr_2);
free(ptr_3);
return 0;
}
4. Write a program to store an integer in block of memory space created by malloc and then modify
the same to store a large integer
Solution:
Enrollment No.:
*******
Enrollment No.: