Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Program to check if given strings form an acrostic

Posted By: Hildemare Miller     Category: C Programming     Views: 3043

Program to check if given strings form an acrostic.

Code for Program to check if given strings form an acrostic in C Programming

#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 ; elsebreak ; } if ( i == 15 ) return 1 ; elsereturn 0 ; }
  
Share: 


Didn't find what you were looking for? Find more on Program to check if given strings form an acrostic Or get search suggestion and latest updates.

Hildemare Miller
Hildemare Miller author of Program to check if given strings form an acrostic is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!