c program to read a string from a file

Write a c program to read a string from a file


<< Go to Index Page >>

Comments

  1. #include
    int main()
    {
    FILE *fp;
    char buff[255];
    fp=fopen("C:/test","r");
    fscanf(fp,"%s",buff);
    printf("%s\n",buff);
    return 0;
    }

    ReplyDelete
  2. #include
    #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;
    }

    ReplyDelete
  3. Md Aminul Islam Tushar
    ID#201710063

    https://pastebin.com/kg5zucL8

    ReplyDelete
  4. //C++ program to write and read text in/from file.
    #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;
    }

    ReplyDelete
  5. Name: Yeasmin Sultana
    ID: 201710251
    solution link: https://ideone.com/py4FSX

    ReplyDelete
  6. #include

    #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

    ReplyDelete
  7. https://drive.google.com/open?id=1DROknTdZ63K0twjNp_f3CFoopW8XiiQJ

    ReplyDelete
  8. https://drive.google.com/open?id=1X-IHf5OXS_Qw5mUyFZxO2p8yUg2TOXBo

    ReplyDelete
  9. https://drive.google.com/open?id=12cMmuzxSaf_5oSXULTDUzekn7Jo_VyRP

    ReplyDelete
  10. https://drive.google.com/open?id=1c7GRMEnp2qgT_nH4xUntz3Qk8Q91obf9

    ReplyDelete
  11. /////////////////////
    // 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();
    }

    ReplyDelete
  12. #include

    int 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

    ReplyDelete
  13. #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();
    }

    ReplyDelete

Post a Comment