[Solved] How to increment the string value? [duplicate]

[ad_1] Integer.parseInt(a+1); parses the String that results from concatenating the value of the String a (“1”) to the int literal 1, which is “11”. Change it to int inc = Integer.parseInt(a) + 1; This way “a” would be parsed to the integer 1 and then 1 would be added to it to give you the … Read more

[Solved] Not able to figure out the logical error in my code

[ad_1] Generally, the logic of your code is OK except a return value mistake in the empty() function. In the empty(), it should return 1 while stack is empty. int empty(){ if(top==-1) return(0); <– !!! here should return 1 } Otherwise, it will go into the while loop at while(precedence(value)<=precedence(stack[top])&&!empty()) even when stack is empty. … Read more

[Solved] Perl: string manipulation – surrounding a word with a character ‘@’

[ad_1] Whenever you need some reasonably common matching problem resolve in Perl, you should always first check the Regexp::Common family on CPAN. In this case: Regexp::Common::Email::Address. From POD Synopsys: use Regexp::Common qw[Email::Address]; use Email::Address; while (<>) { my (@found) = /($RE{Email}{Address})/g; my (@addrs) = map $_->address, Email::Address->parse(“@found”); print “X-Addresses: “, join(“, “, @addrs), “\n”; } … Read more

[Solved] a program to reverse each word in a string( ive read the previous solutions but im looking for one using the functions i only here [closed]

[ad_1] #include <stdio.h> #include <string.h> #include <conio.h> int main(void){ char A[81][81] = {0}; int t=0,j=1,k=0,l; puts(“Input a sentence (max 80 character)”); scanf(“%80[^\n]”, A[0]);//’gets’ has already been abolished, it should explore a different way. while (A[0][t] != ‘\0’){ if(A[0][t] == ‘ ‘){ ++j; k=0; while(A[0][t] == ‘ ‘)//Skip spaces ++t; } else { A[j][k++] = A[0][t++]; … Read more

[Solved] Remove trailing NULL terminator

[ad_1] I suppose easier way to do this is: size_t len = strlen(buf); // will calculate number of non-0 symbols before first 0 char * newBuf = (char *)malloc(len); // allocate memory for new array, don’t forget to free it later memcpy(newBuf, buf, len); // copy data from old buf to new one 7 [ad_2] … Read more

[Solved] calculate frequency of each letter in a string

[ad_1] There are two problems here. First, while std::string is null-terminated (required in C++11, de facto in most implementations before that), you cannot access past size(). If you used string::at() directly, then you’d get hit: reference at(size_type pos);      Throws: out_of_range if pos >= size() which would be true for the null terminator. So the right … Read more

[Solved] Weird results in c [closed]

[ad_1] In addition to LihOs answer above this block looks wrong: if(tab1[i] != ‘\0′) tab1[i]==result[i]; else if (tab2[i] !=’\0′) tab2[i]==result[i]; else printf(” “); Don’t you mean to assign the value in tab1[i]or tab2[i] to result[i]like this? if(tab1[i] != ‘\0′) result[i] = tab1[i]; else if (tab2[i] !=’\0’) result[i] = tab2[i]; else printf(” “); Also using magic … Read more

[Solved] Can anyone help me how to creat a c program prints the center of the words inside a sentance? [closed]

[ad_1] Here’s my solution: #include <stdio.h> int main() { char sentence [100]; int i,letter_count=0; printf(“Enter a sentence: “); fgets(sentence,100,stdin); for(i=0;sentence [i]!=’\0′;i++) { if(sentence [i]==’ ‘ || sentence [i+1]==’\0’) { if(letter_count%2==1) { printf(“%c “,sentence [i-letter_count/2-1]); } letter_count=0; } else { letter_count++; } } putchar(‘\n’); return 0; } 2 [ad_2] solved Can anyone help me how to … Read more

[Solved] Deleted words from a string

[ad_1] Use String.Replace(): string x = @”documents\bin\debug”; string desiredString = x.Replace(@”\bin\debug”, String.Empty); Note: The key thing here is that you have to assign the string returned by the Replace() function to a variable. (From your comment on the question, it is the problem). This can either be another variable (as in the above example) or … Read more

[Solved] How to get only first object value key value [closed]

[ad_1] Just use array[0].value: var array = [{ label: “1”, value: “11” }, { label: “2”, value: “22” }, { label: “3”, value: “33” }, { label: “4”, value: “44” }, ]; var firstValue = array[0].value; console.log(firstValue); You can also use destructuring like so: var array = [{ label: “1”, value: “11” }, { label: … Read more