Index-1              Index-2              Home Page

c program to read a string from a file and write it to the another file

Write a c program to read a string from a file and write it to the another file


<< Go to Index Page >>

17 comments:

  1. #include
    #include
    int main()
    {
    char ch,source_file[20],target_file[20];
    FILE *source, *target;
    printf("Enter name of File to Copy:\n");
    gets(source_file);
    source=fopen(source_file,"r");
    if(source==NULL)
    {
    printf("Press any key to exit.");
    exit(EXIT_FAILURE);
    }
    printf("Enter name of target File:\n");
    gets(target_file);
    target=fopen(target_file,"w");
    if(target==NULL)
    {
    fclose(source);
    printf("Press any key to exit.");
    exit(EXIT_FAILURE);
    }
    while((ch=fgetc(source))!=EOF)
    fputc(ch,target);
    printf("File copied Successfully");
    fclose(source);
    fclose(target);
    return 0;
    }

    ReplyDelete
  2. Md. Aminul Islam Tushar
    ID#201710063

    https://pastebin.com/bM30m01d

    ReplyDelete
  3. Md. Aminul Islam Tushar
    ID#201710063

    https://pastebin.com/bM30m01d

    ReplyDelete
  4. Name: Yeasmin Sultana
    ID: 201710251
    solution link: https://ideone.com/RXGrVl

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

    ReplyDelete
  6. https://drive.google.com/open?id=17X1F5MjDQEHsB3Xuq0lGNh3Eg5TkWohc

    ReplyDelete
  7. https://drive.google.com/open?id=1GETfwJ80rQgH3iti0OwpHJYw-uf2tyCL

    ReplyDelete
  8. https://drive.google.com/open?id=17X1F5MjDQEHsB3Xuq0lGNh3Eg5TkWohc

    ReplyDelete
  9. https://drive.google.com/open?id=1GETfwJ80rQgH3iti0OwpHJYw-uf2tyCL

    ReplyDelete
  10. ** C++ program to count vowels and consonants in a string :
    #include
    #include
    using namespace std;
    int main(){
    char str[200];
    int vowelCounter = 0, consonantCounter = 0;
    cout << "Enter any string: ";
    cin.getline(str, 300);
    for(int i = 0; str[i]!='\0'; i++) {
    if(str[i]=='a' || str[i]=='e' || str[i]=='i' ||
    str[i]=='o' || str[i]=='u' || str[i]=='A' ||
    str[i]=='E' || str[i]=='I' || str[i]=='O' ||
    str[i]=='U')
    {
    vowelCounter++;
    }
    else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z'))
    {
    consonantCounter++;
    }
    }
    cout << "Vowels in String: " << vowelCounter << endl;
    cout << "Consonants in String: " << consonantCounter << endl;
    getch();
    }

    ReplyDelete
  11. https://drive.google.com/open?id=1fbdQWyfRl50s4Q0VA2J5fatAE9-f_DoX

    ReplyDelete
  12. https://drive.google.com/open?id=1GSbK0jWgTIR1XMtcRBHDZTQrisximoHi

    ReplyDelete
  13. https://drive.google.com/open?id=1fbdQWyfRl50s4Q0VA2J5fatAE9-f_DoX

    ReplyDelete
  14. https://drive.google.com/open?id=1GSbK0jWgTIR1XMtcRBHDZTQrisximoHi

    ReplyDelete
  15. /////////////////////
    // Khorshed Alam //
    // ID: 201730438 //
    // 56 batch, CSE //
    /////////////////////

    #include <iostream>
    #include <fstream>

    using namespace std;

    class homeWork{
    public:
    string readFile(){
    string file_data;
    string line_;
    ifstream file_("example.txt");
    //file_.open("example.txt");
    if (file_.is_open()){
    while(getline(file_,line_)){
    file_data += line_+"\n";
    }
    file_.close();
    cout <<"File data read successful from example.txt."<< endl;
    } else {
    cout <<"example.txt file not found!" << endl;
    }
    return file_data;
    }

    wrightFile(string data){
    ofstream file_("example1.txt", std::ofstream::out | std::ofstream::trunc);
    if (file_.is_open()){
    file_ <example1.txt file not found!" << endl;
    return -1;
    }
    }
    };
    main() {
    string data;
    homeWork hw;
    //hw.readFile();
    data = hw.readFile();
    hw.wrightFile(data);
    }

    ReplyDelete
  16. #include
    #include
    #include
    #include
    using namespace std;
    class homeWork{
    public:
    readWright(){
    string file_data;
    string line_;
    ifstream file_("example.txt");
    //file_.open("example.txt");
    if (file_.is_open()){
    while(getline(file_,line_)){
    file_data += line_+"\n";
    }
    file_.close();
    cout <<"> File data read successful from example.txt."<< endl;
    } else {
    cout <<"> example.txt file not found!" << endl;
    }

    ofstream file("example1.txt", std::ofstream::out | std::ofstream::trunc);
    if (file.is_open()){
    file < File write successful to example1.txt." << endl;
    } else {
    cout <<">example1.txt file not found!" << endl;
    return -1;
    }
    }
    };
    main() {
    homeWork hw;
    hw.readWright();
    }

    ReplyDelete
  17. #include
    #include
    #include
    #include
    using namespace std;
    class homeWork{
    public:
    counter(){
    int vowel, consonant, alphabet, arithmetic, numeric, special, word, sentence;
    vowel = consonant = alphabet = arithmetic = numeric = special = word = sentence = 0;

    char ch[] = "Hello this is nothing. for you 10+2+3=6 and nothing *#.";

    for(int i=1; ch[i] != '\0'; i++){
    if ((ch[i] >= 'A' && ch[i] <= 'Z') || (ch[i] >= 'a' && ch[i] <= 'z')){
    if(ch[i]=='A' || ch[i]=='a' || ch[i]=='E' || ch[i]=='e' || ch[i]=='I' || ch[i]=='i' || ch[i]=='O' || ch[i]=='o' || ch[i]=='U' || ch[i]=='u'){
    vowel++;
    } else {
    consonant++;
    }
    alphabet++;
    } else if (ch[i]=='0' || ch[i]=='1' || ch[i]=='2' || ch[i]=='3' || ch[i]=='4' || ch[i]=='5' || ch[i]=='6' || ch[i]=='7' || ch[i]=='8' || ch[i]=='9'){
    numeric++;
    } else if (ch[i] == ' '){
    word++;
    } else if (ch[i] == '.'){
    sentence++;
    } else{
    if(ch[i]=='+' || ch[i]=='-' || ch[i]=='*' || ch[i]=='/' || ch[i]=='%'){
    arithmetic++;
    } else {
    special++;
    }
    }
    }

    cout<<"Total number of vowel is :"< Result stored in example.txt file." << endl;
    } else {
    cout <<"> File not found!" << endl;
    return -1;
    }
    }

    };
    main() {
    homeWork hw;
    hw.counter();

    }

    ReplyDelete