Help getting started..matrices

This is a discussion on Help getting started..matrices within the C Programming forums, part of the General Programming Boards category; I need some help getting started multiplying matrices. This is the pseudocode i am given. Code: int main(int argc, char ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    22

    Help getting started..matrices

    I need some help getting started multiplying matrices.

    This is the pseudocode i am given.

    Code:
    int main(int argc, char **argv) {
    step 1: check if the command line arguments are passed correctly
    step 2: read the first matrix from file and store it in an array
    step 3: read the second matrix from file and store it in an array
    step 4: check if the two matrices are multiplicable
    step 5: multiply the two matrices and store the product in an array
    step 6: print out the product in readable format
    } /* main() */
    I know you arent supposed to do my hw but can you get me started?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    There aren't a whole lot of steps (as in, none) between "reading the pseudocode step" and "writing C code that does exactly that". If it's not given in the assignment, you'll have to decide what the command line arguments are supposed to look like. You'll have to know how the numbers are stored in the files (are the dimensions given? etc.) You'll have to know how to multiply matrices, I guess, and you'll probably have to know how to create a two-dimensional matrix on-the-fly (since the dimensions of the result appear not to be specified ahead of time).

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    22
    Writing the c code is where I have trouble.

    the command line arguments should look like

    program.exe filea.txt fileb.txt

    the number are stored in the files in rows and columns separated by spaces, dimensions ARE given in the file.

    I have the multiplication of matrices coded, I really just need help with specifying the arguments in C which the user types in.

    I can get 2 numbers corresponding to each row and column in 2 matrices to multiply but how do i get the program to read the files the user types then multiply them and store it in an array?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    1. So make sure that there are two command-line arguments. That is, argc must equal three (or at least three, if you'll allow them to type extra stuff).

    2. Open the file, read in the dimensions, create a two-dimensional array with those dimensions, and then crank out a for loop that reads all the rest of the numbers.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    22
    OK, can you help me with error outputs for unrecognized arguments. How can i get it so if the user doesn't type the right argument types(.txt file) it will print an error. I have a switch, but what can i put in the case so it will be ony a .txt file will be recognized, as in what goes in the '*txt' part of the case?
    Code:
    case '*.txt':
                            (start function for program)
    do you get what im trying to do?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You can verify that the file name has .txt in it. You probably shouldn't, but you can -- just search for .txt in argv[1] and argv[2]; if you find it hooray, if you don't boo.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    22
    what is the function for searching within an argument?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If searching within a string, look at that chapter called "Strings" in your book -- you're probably looking for strstr.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C simple Matrices
    By Cyberman86 in forum C Programming
    Replies: 3
    Last Post: 05-07-2009, 05:20 PM
  2. adding matrices, help with switches
    By quiet_forever in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2007, 08:21 AM
  3. Multiplying matrices
    By Star Lancer in forum C++ Programming
    Replies: 7
    Last Post: 05-22-2003, 06:07 AM
  4. Problem multiplying rotation matrices together
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-04-2003, 08:20 AM
  5. How to get started?
    By anoopks in forum Linux Programming
    Replies: 0
    Last Post: 01-14-2003, 02:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21