From e33298e2355157e25b75d97e38875f2806df8144 Mon Sep 17 00:00:00 2001 From: avniagarwal23 <113287146+avniagarwal23@users.noreply.github.com> Date: Fri, 14 Oct 2022 13:34:10 +0530 Subject: [PATCH] Create reverse a string with spaces using 2d arrays This a code for reversing a string with spaces using 2d arrays --- ...verse a string with spaces using 2d arrays | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 algorithms/C/strings/reverse a string with spaces using 2d arrays diff --git a/algorithms/C/strings/reverse a string with spaces using 2d arrays b/algorithms/C/strings/reverse a string with spaces using 2d arrays new file mode 100644 index 00000000..23ba6286 --- /dev/null +++ b/algorithms/C/strings/reverse a string with spaces using 2d arrays @@ -0,0 +1,45 @@ +#include +#include +int main() +{ + char s1[100][100],s[100]; + int k=0,j=0,i,n; + printf("Enter the string: "); + gets(s); // K DENOTES NUMBER OF WORDS + for(i=0;s[i]!='\0';i++) // J DENOTES WORD LENGTH + { + if(s[i]==' ') + { + s1[k][j]='\0'; //REVERSE A STRING + //AVNI AGARWAL + //INVA LAWRAGA + k++; + j=0; + } + else + { + s1[k][j]=s[i]; + j++; + } + } + s1[k][j]='\0'; + + for(i=0;i<=k;i++) + { + n=strlen(s1[i])-1; + + for(j=0;j