INTERVIEW QUESTIONS
C
STRINGS IN C
DETAILS
Question: How to get string in files and print the string in the reverse order?
Answer: int main() { char str[] = ""; FILE *fp,*fp1; int i=0; fp = fopen("a.txt","r");//Source file fp1 = fopen("b.txt","w");//Target file if (fp == NULL) { printf(" Cannot open the file"); return -1; } while( !feof(fp)) { str[i] = fgetc(fp); if(str[i] == ' ') { str[i+1]='
|
Question:
How to get string in files and print the string in the reverse order?
Answer:
int main() { char str[] = ""; FILE *fp,*fp1; int i=0; fp = fopen("a.txt","r");//Source file fp1 = fopen("b.txt","w");//Target file if (fp == NULL) { printf(" Cannot open the file"); return -1; } while( !feof(fp)) { str[i] = fgetc(fp); if(str[i] == ' ') { str[i+1]=' Source: CoolInterview.com
Answered by: Syed Baseer Ahmed | Date: 1/25/2008
| Contact Syed Baseer Ahmed
I think using push and pop you can do it.
int i, j; char c[],y[]; c[i]=get char(); push; pop y[j]=put char();
while (c[i] != ) begin if(c[i]=y[j]) print(both strings are equal); else print ("both are not equal"); end Source: CoolInterview.com
Answered by: ramarao | Date: 1/28/2008
| Contact ramarao
#include <Stdio.h> void main() { chr *s ,*t; int i; fp=fopen("File Name "+b); fscanf(fp,"%s",s); *s=*t; while(*t!=NULL) { t++; i++; }
while(i--) printf("%c",*t)
printf("%c",*t);
} Source: CoolInterview.com
Answered by: Jayakumar | Date: 2/3/2008
| Contact Jayakumar
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|