Thread: Need little help, please..

  1. #1
    Registered User
    Join Date
    Mar 2022
    Posts
    2

    Need little help, please..

    Hi, guys.
    i need your help, a professional help with C, i got a little challenge and i wanted to know how to start and finish this code.
    i will glad that you guys will show me the solution that i will learn from.
    thank you.
    so the work is:
    1.Write a program that receives a file name in the command prompt. The file contains words separated by spaces or
    In line descent.
    2. The program receives from the user a sequence of letters (uppercase or lowercase) and prints all the lines that contain the sequence
    The letters.
    3. If the number N is entered, the program will print a sequence of 5 characters starting with N characters from the beginning of each line. To the extent
    And the number of characters greater than the length of the line will not print anything. If there are no 5 characters left in the same line they will only be printed
    The characters to the end of the line.
    4. The program will continue to receive letters or numbers from the user. The program will exit when an empty string is received.

    thank you!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,426
    "i will glad that you guys will show me the solution that i will learn from."
    And how many other "solutions" have you "learnt from" for you previous assignments?

    Copy/pasting the assignment to a forum isn't good enough.

    You need to make an actual effort, then we help you with where you went wrong.

    Just spoon-feeding you an answer you can copy/paste back to your tutor isn't teaching you anything about "how it's done".
    Any more than visiting a restaurant and eating the food there tells you how to cook.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2022
    Posts
    2
    I do have a beggining and i will glad to share, but i wanted to see another suggestion.
    Code:
            ptr = fopen("test.txt", "a+");
    
    
            if (NULL == ptr) {
                printf("file can't be opened \n");
                break;
            }
    
    
            printf("q2: \n");
    
    
            printf("enter charcters: \n");
    
    
            fgets(inp, 4, stdin);
    and who told that i will "just copy" and spoon feeding? maybe i will sit and start to check others assignments codes?
    Last edited by Elvin; 03-19-2022 at 06:48 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,426
    > 1.Write a program that receives a file name in the command prompt. The file contains words separated by spaces or In line descent.

    ...

    > ptr = fopen("test.txt", "a+");
    How does this meet the very first statement of what the program is to do?



    So you don't wander off due to lack of focus, try starting with an empty program with your assignment as comments.
    Code:
    int main ( ) {
        // 1.Write a program that receives a file name in the command prompt.
        //!! Hint: do a search for argc, argv
        
        // The file contains words separated by spaces or In line descent.
        //!! how many words, how long are the words?
        //!! do you have an idea as to how you would store the words?
    
        //!! before you go on to step 2, try printing out all the words you read, to make sure it's right.
        //!! no point searching for words if your input is broken.
    
        
        // 2. The program receives from the user a sequence of letters (uppercase or lowercase) 
        // and prints all the lines that contain the sequence The letters.
        
        // 3. If the number N is entered, the program will print a sequence of 5 characters 
        // starting with N characters from the beginning of each line. 
        
        // To the extent And the number of characters greater than the length of the line 
        // will not print anything. If there are no 5 characters left in the same line they will only be printed
        // The characters to the end of the line.
        
        // 4. The program will continue to receive letters or numbers from the user. 
        // The program will exit when an empty string is received.
    }
    Let's see if you can get past point 1.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Tags for this Thread