|
It's Logical
Write a function that takes the address of a two-dimensional array, the number of rows and columns, and a string as parameters! The function should create a new one-dimensional array of integers with as many elements as the number of columns in the original array.
The function should fill the new array with Boolean values. An element should be true if the string taken as the fourth parameter occurs in the corresponding column of the original two-dimensional array. The function should return the address of the new array.
The Specification of the Function
int *logical( char *[], int, int, char * );
Note
Place the function in a file named logical.c and submit this file as a solution to the evaluation system. You can test your solution using the following files. The evaluation system does not necessarily perform the evaluation using these files.
myheader.h
#ifndef _MYHEADER_H #define _MYHEADER_H 1
int *logical( char *[], int, int, char * );
#endif /* myheader.h */
download as text file
main.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "myheader.h"
#define N 3 #define M 4 int main() { char *t[ N ][ M ] = { { "szaxofon", "szaxofon", "szaxofon", "szaxofon" }, { "szaxofon", "kakukktojas", "szaxofon", "szaxofon" }, { "szaxofon", "szaxofon", "szaxofon", "kakukktojas" } }; char str[ 100 ]; int i, j; int *p;
strcpy( str, "kakukktojas" ); printf( "%d %d *%s*\n\n", N, M, str ); for ( i = 0; i < N; ++i ) { for ( j = 0; j < M; ++j ) { if ( j > 0 ) putchar( ' ' ); printf( "*%s*", t[ i ][ j ] ); } putchar( '\n' ); } putchar( '\n' ); p = logical( &t[ 0 ][ 0 ], N, M, str ); for ( i = 0; i < N; ++i ) { for ( j = 0; j < M; ++j ) { if ( j > 0 ) putchar( ' ' ); printf( "*%s*", t[ i ][ j ] ); } putchar( '\n' ); } putchar( '\n' ); for ( j = 0; j < M; ++j ) { if ( j > 0 ) putchar( ' ' ); printf( "%d", p[ j ] ); } putchar( '\n' ); free( p ); return EXIT_SUCCESS; }
download as text file
Makefile
CC = gcc OBJS = main.o logical.o TARGETS = main
all: $(TARGETS)
main: main.o logical.o $(CC) main.o logical.o -o main
main.o: main.c $(CC) -c main.c
logical.o: logical.c $(CC) -c logical.c
clean: rm -rf $(OBJS) *~ $(TARGETS)
download as text file
Output of the Sample Test Program
3 4 *kakukktojas*
*szaxofon* *szaxofon* *szaxofon* *szaxofon* *szaxofon* *kakukktojas* *szaxofon* *szaxofon* *szaxofon* *szaxofon* *szaxofon* *kakukktojas*
*szaxofon* *szaxofon* *szaxofon* *szaxofon* *szaxofon* *kakukktojas* *szaxofon* *szaxofon* *szaxofon* *szaxofon* *szaxofon* *kakukktojas*
0 1 0 1
download as text file
Acknowledgement
This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
|
|