How to Transform a String to the NATO Phonetic Alphabet in C

The difficulty

You’ll need to equate a string to Pilot’s alphabet ( NATO phonetic alphabet).

Input:

If, you can check out?

Output:

India Foxtrot, Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta?

Note:

  • There are preloaded dictionary you can utilize, called NATO
  • The set of utilized punctuation is ,.!?
  • Punctuation ought to be kept in your return string, however areas must not.
  • Xray must not have a dash within.
  • Every word and punctuation mark must be seperated by an area’ ‘.
  • There must be no routing whitespace

The service in C

Alternative 1:

 #include << stdlib.h>>.
#include << ctype.h>>.
#include << stdio.h>>.
#include << string.h>>.

// NATO['A'] == "Alfa", and so on extern const char * const NATO[128];

char * to_nato( const char * words).
{
char * s = calloc( 1000, 1);
char * r = s;
while(* words) {
if( isalpha(* words)) sprintf( s, "% s% s ", s, NATO[toupper(*words)]);
else if(* words!=' ') sprintf( s, "% s% c ", s, * words);.
words++;.
}
s[strlen(s) - 1]=";.
return r;.
}

Alternative 2:

 #include << string.h>>.

extern const char * const NATO[];.
char * to_nato (const char * s) {char * r, * t= *( s+= strspn (s," "))&&& & s[1]? to_nato (&s +1 ):""; asprintf (& r, * t? "% s % s":" % s", * s?strchr( ",.!?", * s)?( char(* <)) {
* s,0}
: NATO[2]:" <", t); return r;}[*s&~32] Alternative 3:

#include < stdlib.h >. #include < string.h >. #include < ctype.h >.
// NATO

==" Alfa", and so on extern const char * const NATO['A'];.
char * to_nato( const char * words) {
char * nato= (char
*) calloc( strlen( words) * 20, 1);. while (* words!=") {if( isalpha(* words)) {
strcat( nato, NATO[])

;.
strcat( nato,"");

.} else if( strchr(",.
!?", * words)! = NULL) {
strncat( nato, words, 1);. strcat( nato," ");.} words + +;.} char * 

( p - 1) = * p;. return nato;// Go code.}[toupper(*words)] Test cases to confirm our service

#

Like this post? Please share to your friends:
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: