arrays - Fatal Runtime Error - C Functions -
i trying create function capitalises chars in array.
#include <stdio.h> #include <string.h> void capitaliser(char inputtext[]) { int counter; char upperletter; char lowerletter; (counter = 0; counter < 26; counter++) { lowerletter = 'a'; (char upperletter = 'a'; upperletter <= 'z'; upperletter++) { if(inputtext[counter] == lowerletter) inputtext[counter] = upperletter; lowerletter++; } } } int main( void ) { int counter; char array1[26]; = {'\0'}; char array2[26]; = {'\0'}; scanf("%s %s", array1, array2); capitaliser(array1[26]); capitaliser(array2[26]); ( counter = 0; counter < 26; counter++ ) { printf("\n%c %c", array1[counter], array2[counter]); } }
when code function placed in main , 'inputtext' replaced either 'array1' or 'array2' program runs fine , gives desired outputs. however, when try run code function greeted 'fatal runtime error'.
from assume setting function incorrectly. missing incredibly obvious?
in expression
capitaliser(array1[26])
array[26]
passes twenty-seventh element of array array1
function, converted pointer. first of all, index out of bounds of array, secondly passing single character converted pointer not pass valid pointer.
you want e.g.
capitaliser(array1)
note lack of indexing.
Comments
Post a Comment