hi guys im new to the site im from south africa...im currently in my second year of electrical engineering and now my college has forced me to do software design and ive never had any experience with programing and the others have cause they had programming 1...so my problem now is i got an assignment on 2d arrays and i have no clue how to go at its greek to me if someone could just give me pointers on how to this it would be awesome...

here is the assignment....

A1  
Software Design 2 – Assignment A1

Outcome 1:
The student should be able to identify the need for an array in a program and perform various data manipulations on arrays.

Create a 2d array called alpha with dimensions 5x208 that will contain alphabet characters i.e.

xHxxxxHx
xHxxxxHx
xHHHHHx
xHxxxxHx
xHxxxxHx

(‘x’ represents white spaces)

Write a C program that will prompt the user to enter a character array (max 9 alphabet characters and may only be capital letters), and then display the text entered as a scrolling banner across the screen from left to right. The colours of the characters should be generated randomly.

When the user hits the ENTER key sort the entered array ascending and display as a stationary banner in the middle of the screen.

Hint1: The kbhit() function returns true if a key has been hit
Hint2: The sleep() function is a UNIX function that receives an integer that represents the milliseconds the computer has to pause.

Key = 0;
while(!kbhit() && key != 27)
{
    Key = getch();
}

This segment of code will make the program loop until the ENTER key is pressed

Good Luck!!!

im using dev c++ to program guys....with thanx from desperate and clueless....

Recommended Answers

All 5 Replies

>>Create a 2d array called alpha with dimensions 5x208 that will contain alphabet characters i.e.

That is asking you to create a 2d character array that can contain 5 strings and each string can contain up to 208 characters. Like this: char alpha[5][208];

Did you mean something like this:

#include <stdio.h>
#include <stdlib.h>

#define NUM_OF_ELEMENTS 2

void createAlpha(char **&data, int elements);

int main()
{
    char ** alpha;

    createAlpha(alpha, NUM_OF_ELEMENTS);

    alpha[0] = (char*) 'H';
    alpha[1] = (char*) 'e';

    fprintf(stdout, "%c%c\n", alpha[0], alpha[1]);

    free(alpha);

    return 0;
}

void createAlpha(char **&data, int elements)
{
    for(int i = 0; i < elements; i++)
    {
        data[i] = (char*) calloc(elements, sizeof(char));
    }
}

???

void createAlpha(char **&data, int elements); Sorry, but that is strictly a C++ feature, not C.

Here is the right way to do it

void createAlpha(char ***data, int elements)
{
    int i;
    char **temp = malloc(elements * sizeof(char *));
    for(i = 0; i < elements; i++)
        temp[i] = 0;
    temp[0] = "Hello";
    temp[1] = "World";
    temp[2] = "Another";
    *data = temp;

}


int main()
{
    char **data = 0;
    int i;
    createAlpha(&data, 10);
    for(i = 0; i < 10 && data[i] != 0; i++)
    {
        printf("%s\n", data[i]);
    }
    return 0;
 
}

void createAlpha(char **&data, int elements); Sorry, but that is strictly a C++ feature, not C.

Sorry, I'm not familiar with C, you'll have to work with pointers in that case ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.