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

Program 30

Code

Uploaded by

hitarthkhatiwala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Program 30

Code

Uploaded by

hitarthkhatiwala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CEUC101: Computer Concepts & Programming 24CE049

Program : 30 a. Write a C program to read a text file ‘Demo.txt’ and print each word
of that file 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:
putw() to write the marks (integer values) into the file. getw() to
read the marks from the file.

fopen() and fclose() to open and close the file

U & P.U. Patel Department of Computer Engineering Page 1


CEUC101: Computer Concepts & Programming 24CE049

Code A:

#i nclude <stdio.h>
vo id 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 = ");


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("\n24AIML021_MAYUR ");

B:

#include <stdio.h>
void main()
{
FILE *F1; int number, i;
printf("Enter marks :");

U & P.U. Patel Department of Computer Engineering Page 2


CEUC101: Computer Concepts & Programming 24CE049

F1 = fopen("marks", "w");
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("\n24AIML021_MAYUR ");
}

Output

U & P.U. Patel Department of Computer Engineering Page 3

You might also like