#include<stdio.h>#include<string.h>int main(){ char varname[]={'p','r','o','g','r','a','m'}; printf("The string is %s\n", varname); return 0;}Naveen VP
#include <iostream>#include<iomanip>#include<string.h>using namespace std;int main(){ char s1[20],s2[20]; cout<<"Enter a string:\n"; cin>>setw(19)>>s1; srtcpy(s2,s1); strrev(s2); if((strcmp(s1,s2))==0) cout<<"string is palindrome\n"; else cout<<"string is not a palindrome\n"; return 0;}showing an error here srtcpy(s2,s1); strrev(s2);
In the program, I couldn't understand the usage of 'string variable' instead of 'char'. Kindly please explain.
#include<stdio.h>//#include<string.h>void main(){ int n; char str[20]; //={"am string"}; printf("Enter a number"); scanf("%d",&n); printf("Enter a String"); scanf("%[^\\n]s",str); printf("The Number You entered is: %d\\n",n); printf("The String You entered is: %s\\n",str);}
What is the syntax and how to use the keyword 'getline'. Please explain elaborately (this single-use is confusing). I couldn't find a proper explanation on the internet.Links to a good explanation are also appreciated.
In the program, we write, scanf("%[^\n]s", string_name).I tried missing the [^\n] part, but the result is virtually the same. Please explain, what exactly is its use in spacing?
#include<stdio.h>void main(){\tchar a;\tchar s[10],s1[10];\tprintf("Enter String: ");\tscanf("%[^\\n]s",s1);\tprintf("Enter string2: ");\tscanf("%[^\\n]s",s);\tprintf("String1: %s\\n",s1);\tprintf("String2: %s",s);\t}Output:Enter String: HimaniEnter string2: String1: HimaniString2: @I am not able to read values in second string.
#include<stdio.h>#include<string.h>int main(){\t char strname[30]="Spoken-Tutorial";\tchar s[]={'a','b','c'}; printf("The string is %s\\n", strname);\tprintf("String: %s\\n",s); return 0;}For the above code output is following:The string is Spoken-TutorialString: abcSpoken-TutorialWhy string s is containing such value?
can we use cin.get() instead of getline
How can I remove the trailing spaces from a string?
clarify the difference between getch() and getc()
27610 visits
Outline:Strings -What is a string -Syntax for declaring a string -Syntax for initializing a string -To read a string from keyboard
Strings -What is a string -Syntax for declaring a string -Syntax for initializing a string -To read a string from keyboard
Show video info
Pre-requisite