+ 2
My code for pig latin works for only single words,can anybody help me how it can be modified to work for sentences
#include <stdio.h> int main() { char word[100]; int i; printf("enter the word\n"); scanf("%s",&word); i=0; while(word[i]!='\0') { i++; } word[i]=word[0]; word[i+1]='a'; word[i+2]='y'; word[i+3]='\0'; word[0]=' '; printf("after changing to pig latin\n"); printf("%s",word); }
9 odpowiedzi
+ 1
Here is java implementation
import java.*;
import java.util.Scanner;
class PigLatin
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
String accept=sc.next();
StringBuilder sb=new StringBuilder(accept);
char copy=sb.charAt(0);
//System.out.println(copy);
StringBuilder delete=sb.deleteCharAt(0);
System.out.println(delete);
System.out.println(sb.append(copy)+"ay");
}
}
0
%[^\n] can be used to read till end but with above code won't that just change the last or first word into pig latin n not the others
0
And coder kitten thanks
But I'm just a beginner n i didn't understand what u said
0
Ok got it but again i dont actually know how to use strtok