Return Character Array
eharetea

Returning character arrays from a function in C.

Character arrays in C.

Date Created:Sunday March 04th, 2007 06:35 PM
Date Modified:Saturday August 02nd, 2008 02:45 PM


#include <stdio.h>

char *GetNoteName();

int main()
{
    printf"%s\n"GetNoteName() );
    return 0;
}

char *GetNoteName(void) 
{ 
        static char notes[12] = "A#BC#D#EF#G#";
        return notes;
}




#include <stdio.h>

void enternumber(int *x);
void printint(int x);
char *return_note_name(int x);

int main()
{
    int sizenote;
    enternumber(&note);
    //printint(note);
    printf("%s\n"return_note_name(note));
    
    return 0;
}

char *return_note_name(int x)
{
    static char note_name[12][6] = {     
                {"A"},
                {"A#/Bb"},
                {"B"},
                {"C"},
                {"C#/Db"},
                {"D"},
                {"D#/Eb"},
                {"E"},
                {"F"},
                {"F#/Gb"},
                {"G"},
                {"G#/Ab"}
                };
    return note_name[x%12];
}

void enternumber(int *x) {
    printf("Enter a number between 1-88\n");
    scanf("%d"x);
}

void printint(int x) {
    printf("%d\n"x);
}




Downloads:
Download: chars.c 215 B
Download: chars2.c 658 B

Please login or Click Here to register for downloads
Creative Commons License
Return Character Array 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