Monday, May 24, 2010

Write c program to delete one character from string without using string handling built in function of c?

e.g.


my string is "hello"


and i want to delete 'l'


so my abnswer will be : "heo"

Write c program to delete one character from string without using string handling built in function of c?
Here it is. Rewrite as you wish:





void Remove(char *p, char ch)


{





char *temp;


temp=p;


while (*temp!=NULL)


{


if (*temp==ch){


while (*temp!=NULL){


*temp=*(temp+1);


if (*temp!=NULL) temp++;


} /*end while*/


temp=p;


} /* end if*/


temp++;


}/*end while*/


} /*end Remove*/





EDIT: C passes everything by value (that is it creates a new variable it copies the contents of parameters into) EXCEPT arrays. It creates pointers to arrays. Thus, in this program the calling function I used is:





int main()


{


/* Declarations*/


char Array[50], ch;





printf("Enter a string:");


gets(Array);








printf("Enter a character to remove:");


ch=getc(stdin);


printf("Your string is:\n%s\n", Array);


Remove(Array, ch);


printf("Your string is:\n%s\n", Array);


return 0;


}








You can send it the name of the array or you can send it %26amp;array[0] or whatever you like.


Convert string into integer with error in c#?

I have following script try to convert string to int64


Int64 MyCompanyID1 = Convert.ToInt64(MyCompany1);


which MyCompanyID1 is string contain "123"


but I get error: Input string was not in a correct format, so I changed to another script:


long MyCompanyID1 = Convert.ToInt64(MyCompany1);


I got same error, any help please? Thanks,

Convert string into integer with error in c#?
My guess is that there are some hidden characters in your string that you are not seeing. Are you sure your string is reallly "123" or are you grabbing it from another function call or input. You can easily tests this by simply setting


MyCompany1 = "123";


then running your convert. It works fine on my end. good luck!
Reply:MyCompanyID1 can't be a string containing "123", because you've already declared it as an integer.

sweet pea

Why would my gdb debugger show me this error? c++?

Here is the error it gave, in my main program the first line is to just cout%26lt;%26lt; 1; It won't even do that without pausing for a long time then giving me a segmentation fault. Anyways here's the error:





Program received signal SIGSEGV, Segmentation fault.


0xff358948 in std::string::_Alloc_hider::_Alloc_hider (this=0xf9018000,


__dat=0xff385ecc "", __a=@0xffbff710)


at /export/home/jco/gnu-sw/src/gcc-3.3.3/sp...


228 /export/home/jco/gnu-sw/src/gcc-3.3.3/sp... No such file or directory.


in /export/home/jco/gnu-sw/src/gcc-3.3.3/sp...


Current language: auto; currently c++

Why would my gdb debugger show me this error? c++?
Yahoo reformats things in ways that are not optimal for programming discussions.





In any case, even if your stuff can across intact it would be hard to figure out the error from the error messages alone. Just post the relevant code. If you are barfing on something like "cout %26lt;%26lt; 1" then it is likely something crazy.


A ring of 10 cm in diameter is suspended from a point 12 cm vertically above the centre by six equal strings.?

The strings are attached to the circumference of the ring at equal intervals, thus keeping the ring in a horizontal plane. The cosine of the angle between two adjacent string is...


A) 2/sqrt(13);


B) 313/338;


C) 5/sqrt(26);


D) 5 sqrt(651)/338;


Kindly explain your answer...

A ring of 10 cm in diameter is suspended from a point 12 cm vertically above the centre by six equal strings.?
The answer is B).


The 6 strings and the 6 ring chords between every 2 suspension points are edges of a regular hexagonal pyramid with a base edge length of 5 (the inscribed regular hexagon's side length is equal to the radius - half of ring's diameter 10) and altitude 12. The right triangle with legs radius (5) and altitude (12) yields the lateral edge's length of 13 and the cosine law, applied to a lateral face (isosceles triangle with sides 5, 13 and 13) yields the answer:


(13² + 13² - 5²)/(2*13*13) = (338 - 25)/338 = 313/338

bottle palm

Is the Schecter C-5 bass a good five string?

You can get one new for $550, Im gonna try to find one used though.

Is the Schecter C-5 bass a good five string?
my friend has one and it sounds and feels really good...for 550 thats a good deal





AE
Reply:schecter is a very good brand. i got my ex an a-7 elite guitar for his b-day a few years ago.... beautiful guitar. if you can't find a used c-5, then you should def get a new one... it's worth the money .


Using regular expressions in C++?

If you have a string of text





(for example, "1234 quick 1234 brown 1234 fox")





and you wanted to use a regular expression to identify any words in that string of text, what is the c++ code that would do it?





Note: A word is defined as any sequence of letters that is not interrupted by a space.





I could really use an example of code.





What #include statements would I need? Is there a way to do it without including regex? Where do I get regex (if I try to include it now, my compiler gives me an error, so I assume I need to get it from somewhere)?





Please note, I don't need a tutorial on regular expressions. I understand regular expressions well enough as it is, I just need to know how to use them in C++.

Using regular expressions in C++?
well... one way would be to search through the string until you found a space, or CR/LF.





Im not sure what you want to do when you find them but something like this will count them:





char mystring[] = "1234 quick 1234 brown 1234 fox";


int count, words = 0, spaces = 0, crlf = 0;


BOOL wordsstart = 1;





for (count = 0; count %26lt; sizeof(mystring); count++)


{


if (mystring[count] == 0x20) //space


{


spaces++;


wordstart = 1;


}


else if (mystring[count] == 0x0a || mystring[count] == 0x0d) //carriage return or line feed


{


crlf++;


wordstart = 1;


}


else if (wordstart %26amp;%26amp; ((mystring[count] %26gt;= 'a' %26amp;%26amp; mystring[count] %26lt;= 'z') || (mystring[count] %26gt;= 'A' %26amp;%26amp; mystring[count] %26lt;= 'Z')))


{


words++;


wordstart = 0;


}


}





its just off the top of my head, but it should work
Reply:google up pcre





http://www.pcre.org/!


URGENT HELP PLEASE - Rock on Strings?

https://tycho-s.phys.washington.edu/cgi/...





A 540 gm rock is whirled on the end of a string 45 cm long which will break under a tension of 32 N.


a) What is the highest speed the rock can reach before the string breaks? (Neglect gravity.)





vmax = m/s





HELP: Draw a FBD of rock on string.


b) If two other strings identical to the first were attached to the rock, how fast could the rock be whirled before the three strings would break?





v'max = m/s


Next the rock is held by two of the same 45 cm strings with ends 63 cm apart and whirled in a circle between them. Neglect gravity.





c) What is the radius of the circle of motion?





R = cm


d) Now what is the maximum speed the rock can have before the string breaks?





v''max = m/s

URGENT HELP PLEASE - Rock on Strings?
isnt this your homework??
Reply:Aaaahhh... I know watcha up 2 buddy...