Thread: Help with a program

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    4

    Help with a program

    I need help making a program that read 2 int (the number of "nl" lines and "nc" columns of the word search) and then read the "nl" lines of the word search. After that, my program must read the number of coordinates "n" and, after that, the "n" pairs of coordinates knowing that first reading the number of column "c" and second the number of line "l".

    here's an example:
    3 4
    ABCD
    EFGH
    IJKL
    5
    1 2 1 3 2 2 3 3 2 4

    In this case, my program should print the BCFKH string.

    Can anyone help me?

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    And what have you tried?
    C is fun

  3. #3
    Registered User
    Join Date
    Mar 2014
    Posts
    4
    Quote Originally Posted by KBriggs View Post
    And what have you tried?
    for now, nothing. i'm new to c language and need some guidelines for this

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    You need to show some real effort if you want us to put in real effort toward helping you. Read your textbook and class notes, and check some online tutorials. The scanf and printf family of functions will probably be useful here, as will 2-d arrays.

    Then, if you have trouble, post back, paste your code (as plain text), properly indented and formatted, in [code][/code] tags. Ask specific questions about the specific problems you're having and if necessary, give us as much info as we need to reproduce your problems and help you troubleshoot them.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I suggest read the section called "Introduction and Basic C Features" C Tutorial - Learn C - Cprogramming.com
    You need at least the first three; and, I think the forth would be useful.

    I think after the first three section; you might try reading this FAQ FAQ > Get a line of text from the user/keyboard (C) - Cprogramming.com

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  6. #6
    Registered User
    Join Date
    Dec 2013
    Posts
    24
    well here you go, but next time try something by yourself first, then ask for help. (I did it fast so excuse me for the messy look)
    NOTE: I assumed that the input is clear and good, which means I didn't check if the variables wether the user entered really int or char... check them by yourself if you want.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        char** arr;
        int n,m;
        int i,j,pairs,r,c;
        
        //input rows and columns
        scanf("%d", &n);
        scanf("%d", &m);
    
        //define matrix
        arr=(char**)malloc(n*sizeof(char*));
        for(i=0; i<n; i++)
            arr[i]=(char*)malloc(m*sizeof(char));
    
        //input matrix
        for(i=0;i<n;i++)
            for(j=0;j<m;j++)
                scanf(" %c", &arr[i][j]);
    
        //input number of pairs, and print them...
        scanf("%d", &pairs);
        while(pairs!=0)
        {
            scanf("%d", &r);
            scanf("%d", &c);
            printf("%c", arr[r-1][c-1]);
            pairs--;
        }
        printf("\n");
        
        //free memory
        for(i=0;i<n;i++)
            free(arr[i]);
        free(arr);
    
        return 0;
    }

    hope it helped
    Last edited by ConanCoder; 03-29-2014 at 01:37 PM.

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    @ConcanCoder:
    We do no hand out solutions on this site -- not even on a one-time basis. We are here to help people learn and giving them the answer most certainly does not do that. I suggest you re-read the forum guidelines and homework policy. If you want to give away free solutions, there are other programming forums that don't care.

  8. #8
    Registered User
    Join Date
    Dec 2013
    Posts
    24
    Quote Originally Posted by anduril462 View Post
    @ConcanCoder:
    We do no hand out solutions on this site -- not even on a one-time basis. We are here to help people learn and giving them the answer most certainly does not do that. I suggest you re-read the forum guidelines and homework policy. If you want to give away free solutions, there are other programming forums that don't care.
    Oh okay my bad, thought it's okay if I give him this... I won't do it again I promise :/

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by ConanCoder View Post
    Oh okay my bad, thought it's okay if I give him this... I won't do it again I promise :/
    So, despite being pointed to the homework policy when you asked for help without having applied effort, you concluded it is okay to do people's homework for them?

    A policy of (effectively) "do your own homework" can't logically work if people do homework for others.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  10. #10
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    I wouldn't mark ConanCoder's code that highly...

    The thing that should be noted here is that everytime you give a programmer [to be] a full solution on here, the programming community gets dumber.

    Also, everytime you give a solution out that does not display good programming practices, the programming community gets dumber.
    Fact - Beethoven wrote his first symphony in C

  11. #11
    Registered User
    Join Date
    Dec 2013
    Posts
    24
    you guys, you really need to chill out, you don't tell me what should I do, u r NOT my bosses, even though the rules prevent these things, and grumpy if u don't want to help with homeworks, very well, but what I did wasn't asking for full solution, cuz as u see I tried doing them, and by the way what I'm asking for is not "please code for me this", it's complexity things (which I find most hard), and still, I try doing it by my self be4 I post, and Click_here speak for your self <3

    END OF DISCUSSION, I'm never responding or texting again, just letting you know, you don't tell me what to do. (FULL STOP)

  12. #12
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by ConanCoder
    "but what I did wasn't asking for full solution, cuz as u see I tried doing them..."
    The reason why we were against you posting a solution is because Luis Ribeiro posted the question, not ConanCoder

    Quote Originally Posted by ConanCoder
    "you don't tell me what to do"...
    You should always follow Forum guidelines, and not aid others in breaking the Forum guidelines.
    http://cboard.cprogramming.com/c-pro...e-posting.html
    Last edited by Click_here; 03-30-2014 at 02:40 PM.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-11-2012, 12:25 AM
  2. Replies: 6
    Last Post: 07-14-2012, 09:43 AM
  3. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  4. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  5. Replies: 18
    Last Post: 11-13-2006, 01:11 PM