Thread: Help with Simple Programming

  1. #1
    Registered User
    Join Date
    Jun 2021
    Posts
    1

    Help with Simple Programming

    Hello! I am very new to C programming like literally from the scratch. It's part of my new job and I'm learning. My superior gave me a problem and for the life of me, I don't know how to figure it out.


    How do you put this in C language:
    For example

    Input D 0,3

    where D serves as dump memory (I'm not sure)
    and 0 as the address
    while 3 is the number of arrays or data

    then the ouput will come out as

    buf(0) 00 01 02

    another example

    Input D 5,4

    Output

    buf(5) 06 07 08 09


    I hope my question makes sense hahaha
    It's hard to learn programming if my superior speaks in a foreign language (Japanese) that I'm still not that fluent with

    Thank you very much!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413

    Thumbs up

    I'm guessing that since this is a job rather than school, you already have a sufficiently strong foundational programming background to pass the interview for this internship/junior role, but the issue is that you're completely new to the C programming language?

    The first thing I'd do is to clarify the requirements as to the content of the data items. For example, I see the two sample outputs: "buf(0) 00 01 02" and "buf(5) 06 07 08 09". Initially, I thought that maybe you're supposed to fill the data items starting from 0. Then I see that "06 07 08" and that makes no sense to me. Like, if it means that you start 1 greater than the address, we would expect the first output to be "buf(0) 01 02 03" instead. Then I'd ask what is the format of these numbers: are they in decimal, or perhaps hexadecimal?

    As for solving this with a C program: basically, you're reading a line of input and parsing it. It might be simplest to just have a sufficiently large array of char and then call fgets to read the line of input. As for parsing, there are several possible approaches, e.g., you could check for the "Input D " prefix, then you know exactly where the address and number of data item components begin, so with a little pointer arithmetic you have a pointer to the start of the substring that you can parse with sscanf, strtok + strtol, etc.
    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
    Sep 2020
    Posts
    425
    1) See if there are any local programming standards you have to follow. Indentation, style, portability, licensing, compiler options. Maybe there is a template you can use as the basis for your program.

    2) Work out the rough structure of the program - what does it have to do, how does it stop. Write it down.

    For example
    Code:
    This program must:
    
    Print a hello message
    read a line of input from the user
    while the line of input is not empty
       respond to that line of input
       read another line of input from the user
    Print an exit message
    You should able to use a search engine and a bit of intuition to work out how to do nearly all of those steps in the C programming language, apart from maybe the "respond to that line of input". Maybe when starting out assume that the requirement is to just print "The user entered '.....'", so you can check that works.

    You will then be at the point of inspecting the user's input and acting on it.

    3) If you get here, now you will want to work out how to 'parse' the user input to see if it is valid command, then act on it. When you get that far, come back and ask for more direction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need simple programming help
    By Gbomb in forum C Programming
    Replies: 11
    Last Post: 02-07-2012, 04:51 PM
  2. simple C programming... but i need help PLZ
    By astrosona in forum C Programming
    Replies: 1
    Last Post: 03-04-2009, 08:58 PM
  3. Simple Programming Help Req
    By umar7001 in forum C++ Programming
    Replies: 6
    Last Post: 01-27-2008, 02:34 PM
  4. Simple programming help
    By IxTanGxI in forum C Programming
    Replies: 5
    Last Post: 02-21-2006, 02:00 AM
  5. Help with simple programming
    By jjj93421 in forum C++ Programming
    Replies: 4
    Last Post: 07-31-2004, 07:05 AM

Tags for this Thread