Multidimensional Arrays
eharetea

Using malloc() within Multi-dimensional Arrays in C.

Multiple dimensions with arrays in C.

Date Created:Tuesday May 08th, 2007 04:10 PM
Date Modified:Sunday August 03rd, 2008 12:37 PM


/*
* Author: Dan Lynch
*/

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

void getnamechar ** xint z);
void searchnamechar ** xint n);

int main() {
    char name[4];
    getname(name4);
    searchname(name4);
    return 0;
}

void getnamechar ** xint n) {
    int i;
    char ch[21];
    
    for (i=0i<ni++) {
        printf("Enter Name %d>",i);
        gets(ch);
        x[i]=malloc((strlen(ch)+1)*sizeof(char));
        strcpy(x[i], ch);
    }
}

void searchnamechar ** xint n) {
    int i;
    char q;
    printf("Type a word to search in the array:");
    scanf("%s",q);
    for (i=0i<ni++)
        if (!strcmp(x[i],q)) printf("Match in element x[%d]!\n",i);
        else printf("No match for %s\n",x[i]);
}



Downloads:
Download: code.c 718 B

Please login or Click Here to register for downloads
Creative Commons License
Multidimensional Arrays by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com