|
|
|
| Web Hosting Guide |
Can Anyone Solve This Question In C Programming Language? |
May 4 2009, 07:52 AM
Post
#1
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 1 Joined: 4-May 09 Member No.: 40,052 |
Hi,
Write code to solve the following problem. Define a function that takes a String as a parameter and returns an integer value. The function need to loop through each character in the input string to find a value of “x”. If a value of “x” is found in the string then return the position within the string where “x” is found else return -1. |
|
|
|
![]() |
Replies
(1 - 2)
May 5 2009, 06:24 AM
Post
#2
|
|
|
Premium Member Group: Members Posts: 212 Joined: 7-October 05 From: RMIT University Member No.: 8,966 myCENTs:65.61 |
Hi Stella,
Just a quick question about your problem. Is "x" a string or a character? Hi, Write code to solve the following problem. Define a function that takes a String as a parameter and returns an integer value. The function need to loop through each character in the input string to find a value of “x”. If a value of “x” is found in the string then return the position within the string where “x” is found else return -1. |
|
|
|
May 29 2009, 08:02 PM
Post
#3
|
|
|
Advanced Member Group: [HOSTED] Posts: 160 Joined: 7-November 05 Member No.: 9,489 myCENTs:36.33 |
try this code to see if it is help ~~
CODE #include <stdio.h>
int findpos(char *str, char x); int main(int argc, char **args) { [tab][/tab]char *s = "some gext"; [tab][/tab]int r; [tab][/tab]r = findpos(s, 'g'); [tab][/tab]printf("%d\n", r); } int findpos(char *str, char x) { [tab][/tab]char *s = str; [tab][/tab]int i = 0; [tab][/tab]while (*s && (*s != x)) [tab][/tab]{ [tab][/tab][tab][/tab]++i; ++s; [tab][/tab]} [tab][/tab]return (*s) ? i : -1; } This post has been edited by magiccode9: May 29 2009, 08:04 PM |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
11 | FirefoxRocks | 1,987 | 15th March 2010 - 08:29 AM Last post by: iG-StanB |
|||
![]() |
15 | Normano | 1,462 | 23rd February 2010 - 10:34 PM Last post by: iG- |
|||
![]() |
4 | kanade | 1,191 | 23rd February 2010 - 09:51 PM Last post by: iG-ryanul chowdhury |
|||
![]() |
7 | Jonnyabc | 189 | 17th February 2010 - 08:31 AM Last post by: mastercomputers |
|||
![]() |
24 | lacking_imagination | 6,532 | 15th February 2010 - 03:48 AM Last post by: iG-richard |
|||
![]() |
16 | sandeep | 2,670 | 8th February 2010 - 09:19 AM Last post by: iG-Vikram |
|||
![]() |
49 | bigd1 | 8,475 | 6th February 2010 - 09:07 PM Last post by: iG-t7ancients |
|||
![]() |
103 | miCRoSCoPiC^eaRthLinG | 14,487 | 1st February 2010 - 12:30 PM Last post by: 8ennett |
|||
![]() |
11 | xboxrulz | 1,553 | 21st January 2010 - 06:44 PM Last post by: iG-Komputer professor |
|||
![]() |
4 | Manu Dhanda | 1,199 | 6th January 2010 - 12:39 PM Last post by: iG-medhatalbashaa |
|||
![]() |
2 | turbopowerdmaxsteel | 7,997 | 4th January 2010 - 07:29 AM Last post by: iG-v_tarasu |
|||
![]() |
13 | WeaponX | 1,893 | 31st December 2009 - 03:00 AM Last post by: iG-flip |
|||
![]() |
1 | miCRoSCoPiC^eaRthLinG | 1,361 | 31st December 2009 - 01:16 AM Last post by: iG-mahesh Chander |
|||
![]() |
2 | Feelay | 459 | 9th December 2009 - 01:26 PM Last post by: wutske |
|||
![]() |
17 | MOOSE | 2,944 | 3rd December 2009 - 02:01 PM Last post by: Spencer |
|||
|
Lo-Fi Version | Time is now: 22nd March 2010 - 04:17 AM |
© 2010 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation


May 4 2009, 07:52 AM








