C Programming Blog

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

#define MAX1 5
#define MAX2 6

void main( )
{
    char str[MAX1][MAX2] ;
    int i ;
    int check ( char * ) ;

    clrscr( ) ;

    strcpy ( str[0], \"ROTAS\" ) ;
    strcpy ( str[1], \"OPERA\" ) ;
    strcpy ( str[2], \"TENET\" ) ;
    strcpy ( str[3], \"AREPO\" ) ;
    strcpy ( str[4], \"SATOR\" ) ;

    printf ( \"\\nThe strings are:\\n\" ) ;
    for ( i = 0 ; i < MAX1 ; i++ )
            printf ( \"%s\\n\", str[i] ) ;

    i = check ( str[0] ) ;

    if ( i == 1 )
        printf ( \"The given strings form an acrostic\\n\" ) ;
    else
        printf ( \"The given strings do not form an acrostic\\n\" ) ;

    getch( ) ;
}

/* checks if forms an acrostic */
int check ( char *s )
{
    int i, j ;
    j = ( MAX1 * MAX2 ) - 2 ;

    for ( i = 0 ; i < 15 ; i++, j-- )
    {
        if ( * ( s + i ) == * ( s + j ) )
            continue ;
        else
            break ;
    }

    if ( i == 15 )
        return 1 ;
    else
        return 0 ;
}

 
 
Didn't find what you were looking for? Find more on Program to check if given strings form an acrostic