c program to read a string from a file Get link Facebook Twitter Pinterest Email Other Apps March 05, 2015 Write a c program to read a string from a file << Go to Index Page >> Get link Facebook Twitter Pinterest Email Other Apps Comments Naimul hasan shohan, ID :-201320335September 16, 2015 at 12:36 PM#includeint main(){ FILE *fp; char buff[255]; fp=fopen("C:/test","r"); fscanf(fp,"%s",buff); printf("%s\n",buff); return 0;}ReplyDeleteRepliesReplyUnknownNovember 18, 2015 at 1:45 AM#include#includeint main(){ FILE *fp; char ch[100]; char buff; int i; fp=fopen("E:/FILE/salman.txt","r"); while(fscanf(fp,"%c",&ch[i])!=EOF) { buff=ch[i]; printf("%c",buff); } fclose(fp); return 0;}ReplyDeleteRepliesReplySuratul AsorApril 24, 2016 at 5:39 PMধন্যবাদReplyDeleteRepliesReplyAnonymousJanuary 28, 2019 at 6:05 AMMd Aminul Islam TusharID#201710063https://pastebin.com/kg5zucL8ReplyDeleteRepliesReplySaideJanuary 28, 2019 at 8:21 AM//C++ program to write and read text in/from file.#include #include #includeusing namespace std;int main(){ fstream file; //object of fstream class //opening file "sample.txt" in out(write) mode file.open("sample1.txt",ios::out); if(!file) { cout<<"Error in creating file!!!"<>ch; //read single character from file cout<<ch; } file.close(); //close file return 0;}ReplyDeleteRepliesReplyYeasmin SultanaJanuary 31, 2019 at 10:09 AMName: Yeasmin SultanaID: 201710251solution link: https://ideone.com/py4FSXReplyDeleteRepliesReplyIbrahimFebruary 4, 2019 at 1:47 AM#include #define MAXCHAR 1000int main() { FILE *fp; char str[MAXCHAR]; char* filename = "E:\\Study\\CompilerConstraction\\Practice\\Open\\ibrahim.txt"; fp = fopen(filename, "r"); if (fp == NULL){ printf("Could not open file %s",filename); return 1; } while (fgets(str, MAXCHAR, fp) != NULL) printf("%s", str); fclose(fp); return 0;}ID: 201330475Batch-44thReplyDeleteRepliesReplyUnknownFebruary 5, 2019 at 5:29 AMhttps://drive.google.com/open?id=1DROknTdZ63K0twjNp_f3CFoopW8XiiQJReplyDeleteRepliesReplyUnknownFebruary 5, 2019 at 5:30 AMhttps://drive.google.com/open?id=1X-IHf5OXS_Qw5mUyFZxO2p8yUg2TOXBoReplyDeleteRepliesReplyUnknownFebruary 5, 2019 at 9:51 PMhttps://drive.google.com/open?id=12cMmuzxSaf_5oSXULTDUzekn7Jo_VyRPReplyDeleteRepliesReplyUnknownFebruary 5, 2019 at 9:51 PMhttps://drive.google.com/open?id=1c7GRMEnp2qgT_nH4xUntz3Qk8Q91obf9ReplyDeleteRepliesReplyKhorshed AlamFebruary 7, 2019 at 2:16 AM/////////////////////// Khorshed Alam //// ID: 201730438 //// 56 batch, CSE ///////////////////////#include <iostream>#include <fstream>using namespace std;class homeWork{ public: readFile(){ string line_; ifstream file_("example.txt"); //file_.open("example.txt"); if (file_.is_open()){ cout <<"File contents are showing below :"<< endl; while(getline(file_,line_)){ cout<<"| "< File not found!" << endl; return -1; } }};main() { homeWork hw; hw.readFile();}ReplyDeleteRepliesReplyUnknownFebruary 7, 2019 at 9:37 PM#includeint FindLength(char str[]);int main() { char str[100]; int length; printf("\nEnter the String : "); gets(str); length = FindLength(str); printf("\nLength of the String is : %d", length); return(0);}int FindLength(char str[]) { int len = 0; while (str[len] != '\0') len++; return (len);}ID: 201820244 batch :58thReplyDeleteRepliesReplyUnknownFebruary 7, 2019 at 9:47 PM#include #include #include #include using namespace std;class homeWork{ public:readFile(string data){ string line_; ifstream file_("example.txt"); //file_.open("example.txt"); if (file_.is_open()){ cout <<"> File contents are showing below :"<< endl; while(getline(file_,line_)){ cout<<"| "< File not found!" << endl; return -1; } }};main() { homeWork hw;hw.readFile();}ReplyDeleteRepliesReplyAdd commentLoad more... Post a Comment
#include
ReplyDeleteint main()
{
FILE *fp;
char buff[255];
fp=fopen("C:/test","r");
fscanf(fp,"%s",buff);
printf("%s\n",buff);
return 0;
}
#include
ReplyDelete#include
int main()
{
FILE *fp;
char ch[100];
char buff;
int i;
fp=fopen("E:/FILE/salman.txt","r");
while(fscanf(fp,"%c",&ch[i])!=EOF)
{
buff=ch[i];
printf("%c",buff);
}
fclose(fp);
return 0;
}
ধন্যবাদ
ReplyDeleteMd Aminul Islam Tushar
ReplyDeleteID#201710063
https://pastebin.com/kg5zucL8
//C++ program to write and read text in/from file.
ReplyDelete#include
#include
#include
using namespace std;
int main()
{
fstream file; //object of fstream class
//opening file "sample.txt" in out(write) mode
file.open("sample1.txt",ios::out);
if(!file)
{
cout<<"Error in creating file!!!"<>ch; //read single character from file
cout<<ch;
}
file.close(); //close file
return 0;
}
Name: Yeasmin Sultana
ReplyDeleteID: 201710251
solution link: https://ideone.com/py4FSX
#include
ReplyDelete#define MAXCHAR 1000
int main() {
FILE *fp;
char str[MAXCHAR];
char* filename = "E:\\Study\\CompilerConstraction\\Practice\\Open\\ibrahim.txt";
fp = fopen(filename, "r");
if (fp == NULL){
printf("Could not open file %s",filename);
return 1;
}
while (fgets(str, MAXCHAR, fp) != NULL)
printf("%s", str);
fclose(fp);
return 0;
}
ID: 201330475
Batch-44th
https://drive.google.com/open?id=1DROknTdZ63K0twjNp_f3CFoopW8XiiQJ
ReplyDeletehttps://drive.google.com/open?id=1X-IHf5OXS_Qw5mUyFZxO2p8yUg2TOXBo
ReplyDeletehttps://drive.google.com/open?id=12cMmuzxSaf_5oSXULTDUzekn7Jo_VyRP
ReplyDeletehttps://drive.google.com/open?id=1c7GRMEnp2qgT_nH4xUntz3Qk8Q91obf9
ReplyDelete/////////////////////
ReplyDelete// Khorshed Alam //
// ID: 201730438 //
// 56 batch, CSE //
/////////////////////
#include <iostream>
#include <fstream>
using namespace std;
class homeWork{
public:
readFile(){
string line_;
ifstream file_("example.txt");
//file_.open("example.txt");
if (file_.is_open()){
cout <<"File contents are showing below :"<< endl;
while(getline(file_,line_)){
cout<<"| "< File not found!" << endl;
return -1;
}
}
};
main() {
homeWork hw;
hw.readFile();
}
#include
ReplyDeleteint FindLength(char str[]);
int main() {
char str[100];
int length;
printf("\nEnter the String : ");
gets(str);
length = FindLength(str);
printf("\nLength of the String is : %d", length);
return(0);
}
int FindLength(char str[]) {
int len = 0;
while (str[len] != '\0')
len++;
return (len);
}
ID: 201820244 batch :58th
#include
ReplyDelete#include
#include
#include
using namespace std;
class homeWork{
public:
readFile(string data){
string line_;
ifstream file_("example.txt");
//file_.open("example.txt");
if (file_.is_open()){
cout <<"> File contents are showing below :"<< endl;
while(getline(file_,line_)){
cout<<"| "< File not found!" << endl;
return -1;
}
}
};
main() {
homeWork hw;
hw.readFile();
}