Thread: Can someone help or maybe tutor me for an hour on discord?

  1. #1
    Registered User
    Join Date
    Jul 2020
    Posts
    4

    Exclamation Can someone help or maybe tutor me for an hour on discord?

    Hi, i'm new to this website. I'm studying electronics engeneering and my C programming exam is tomorrow, i've been studying 10+ hours a day but i still don't get the grasp of it, even though this is the second time im taking this subject, since i failed it last semester. My professor gave us a sample test that he claims if we can solve it, we will ace the exam, it's about programming a matrix calculator including multiplication, division, adding and subtracting, but for this and the exam we can only use the functions seen in class (stdio library, structs, arrays, creating our own libraries). Since the pandemic forced the university to do all classes in online format, i don't know any classmates that can help me, and i don't know what else to do but to ask for someone to tutor me for an hour in a forum.
    I'll describe the sample test, can't really give you a copy since it's in spanish (i'm pretty decent at speaking english so i don't think that will be a problem):
    -Program must not have stdio functions in the main file, every function and variable must be in .c or .h external libraries.
    -The variable types that you use are not to be evaluated, if it works, it's fine.
    1)Program asks what operation you want to do.
    2)Program asks for the first line of the first matrix, then the next one and so on until user enters $ character, then the same for the second matrix.
    3)Program checks if the matrixes dimensions are compatible for the operation, if they are, the program calculates the result and prints it, then it closes. If they aren't program prints an error message and closes.

    I'm currently striving to get past point 2 since i can't manage to get an entire line of the matrix from a single user input.

    Of course every tip is welcome, thanks for reading.
    Last edited by Paolitros; 07-14-2020 at 07:57 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,909
    Quote Originally Posted by Paolitros
    I'm currently striving to get past point 2 since i can't manage to get an entire line of the matrix from a single user input.
    What is your idea and what have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2020
    Posts
    4
    Declared two int arrays sized [20][20] for the matrixes in the .h file, and i'm trying to make a for loop in a external .c library function to get the multiple numbers from a single scanf, i just learnt that you can get multiple inputs doing this scanf("%i %i %i", num1, num2, num3), but i don't think that it will help since the user must be able to input as many numbers as it wants (i figured a max of 20 would cover it). Also the ammount of time i've spent studying has worn me out so i'm not really progressing much and i'm starting to make obvious mistakes. This is my last failed experiment:
    Code:
    void ingresarMatriz1()
    {
      int numDato = 0;
      int numFila = 0;
      for (numFila = 0; numFila < 20; numFila++) {
        printf
            ("Ingrese fila %i para primera matriz, datos separados por espacios\n",
             numFila + 1);
        for (numDato = 0; numDato < 20; numDato++) {
          scanf("%i", &Matriz1[numFila][numDato]);
          if (Matriz1[numFila][numDato] == '$') {
            break;
          }
        }
        while (getchar() != '\n');
        for (int i = 0; i < 20; i++) {
          printf("%i ", Matriz1[numFila]);
        }
      }
    }
    Last edited by Salem; 07-14-2020 at 10:45 PM. Reason: crayola

  4. #4
    Registered User
    Join Date
    Jul 2020
    Posts
    4
    Update: this worked to get the matrix lines in one input, but having to search for the user inputing $ to break using getchar() eats away the first digit of each number, is there a way to use getchar() without erasing anything from the buffer?
    Code:
    for (int dato = 0; dato < 400; dato++) {
    
      scanf("%i", &Matriz1[fila][dato]);
      if (getchar() == '\n') {
        fila++;
      }
      if (getchar() == '$') {
        break;
      }
    }
    Last edited by Salem; 07-14-2020 at 10:46 PM. Reason: crayola

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,162
    > 2)Program asks for the first line of the first matrix, then the next one and so on until user enters $ character, then the same for the second matrix.
    How do you know the dimensions of the matrix?

    If the user types in 12 numbers say, then you can have choices:
    1x12
    2x6
    3x4
    4x3
    6x2
    12x1
    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.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,909
    Quote Originally Posted by Salem
    How do you know the dimensions of the matrix?
    The user enters the entries row by row, so that is easy to determine. Just need a sanity check to ensure that the rows have the same number of entries.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,162
    So what's with the "until user enters $ character" bit all about then?
    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.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,909
    Quote Originally Posted by Salem
    So what's with the "until user enters $ character" bit all about then?
    A way to determine the last row since the dimensions aren't given in advance, and there's a second matrix to input so you cannot just make use of an EOF condition.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function returning hour in either 12 or 24 hour format
    By stanlvw in forum C Programming
    Replies: 4
    Last Post: 01-01-2008, 06:02 AM
  2. tutor
    By BJtoVisualcC++ in forum Projects and Job Recruitment
    Replies: 21
    Last Post: 06-13-2007, 06:50 AM
  3. Anyone want to tutor me in C++? :P
    By Fuzzy91 in forum C++ Programming
    Replies: 6
    Last Post: 04-11-2006, 10:46 PM
  4. Roidian: Final Hour (72 hour gd compo results)
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 12-29-2004, 10:27 PM
  5. Tutor
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 07-10-2003, 09:03 AM

Tags for this Thread