0% found this document useful (0 votes)
7 views

Program 30

Code

Uploaded by

hitarthkhatiwala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Program 30

Code

Uploaded by

hitarthkhatiwala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CEUC101: Computer concepts & Programming 24AIML019__ Hitarth Khatiwala

Program: a. Write a C program to read a text file ‘Demo.txt’ and print each word of that file
1.30
in reverse order.
Example:
Input: HELLO
Output: OLLEH
b. You are building a simple student marks recording system that:
1. Writes students' marks to a file.
2. Reads the marks from the file.
The program will use:
I putw() to write the marks (integer values) into the file.
II getw() to read the marks from the file.
III fopen() and fclose() to open and close the file

Code A.
#include <stdio.h>
void main()
{
FILE *F1;
char name[50], rev_note[50];
int i, j;
int length = 0;
int number;
F1 = fopen("revers", "w");

printf("Enter a string = ");


CEUC101: Computer concepts & Programming 24AIML019__ Hitarth Khatiwala

gets(name);

fclose(F1);

F1 = fopen("revers", "r");
printf("\n Display :\n");

for (i = 0; name[i] != '\0' /*(name=getw(F1))!=EOF*/; i++)


length++;

for (i = length - 1, j = 0; i >= 0; i--, j++)


rev_note[j] = name[i];
rev_note[j] = '\0';
printf("\nThe reverse note is :");
puts(rev_note);
fclose(F1);
printf("\n24AIML019_HITARTH");
}
-------------------------------------------------------------------------------------------------------
B.
#include <stdio.h>
void main()
{
FILE *F1;
int number, i;
printf("Enter marks :");
F1 = fopen("marks", "w");
CEUC101: Computer concepts & Programming 24AIML019__ Hitarth Khatiwala

for (i = 0; i <= 5; i++)


{
scanf("%d", &number);
putw(number, F1);
}
fclose(F1);
F1 = fopen("marks", "r");
printf("\n Display the marks\n");
while ((number = getw(F1)) != EOF)
printf("%d ", number);
fclose(F1);
printf("\n24AIML019_HITARTH");
}

Output
CEUC101: Computer concepts & Programming 24AIML019__ Hitarth Khatiwala
CEUC101: Computer concepts & Programming 24AIML019__ Hitarth Khatiwala

You might also like