|
|
|
| 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. |
|
|
|
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: 145 Joined: 7-November 05 Member No.: 9,489 myCENTs:33.08 |
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 | |||
|---|---|---|---|---|---|---|---|
![]() |
8 | xboxrulz | 1,243 | Yesterday, 08:31 PM Last post by: iG-Anon |
|||
![]() |
15 | david_ytk | 1,855 | 6th November 2009 - 12:31 PM Last post by: The_Fury |
|||
![]() |
6 | eyvind | 1,974 | 6th November 2009 - 01:52 AM Last post by: The_Fury |
|||
![]() |
5 | sparkx | 684 | 4th November 2009 - 12:29 AM Last post by: HannahI |
|||
![]() |
14 | sandeep | 2,276 | 3rd November 2009 - 09:11 PM Last post by: iG-rick |
|||
![]() |
19 | lonebyrd | 3,521 | 1st November 2009 - 03:49 PM Last post by: iG-Lukenda |
|||
![]() |
0 | MikyZuma | 48 | 24th October 2009 - 10:28 AM Last post by: MikyZuma |
|||
![]() |
12 | WeaponX | 1,609 | 8th October 2009 - 07:59 PM Last post by: HannahI |
|||
![]() |
1 | acdragon | 803 | 5th October 2009 - 08:47 PM Last post by: HannahI |
|||
![]() |
14 | Normano | 1,196 | 3rd October 2009 - 07:44 PM Last post by: iG-anonymous |
|||
![]() |
2 | kanade | 831 | 9th September 2009 - 09:25 AM Last post by: iG-Mohan |
|||
![]() |
1 | t3jem | 3,186 | 20th August 2009 - 01:01 PM Last post by: iG-Patrick Coffman |
|||
![]() |
38 | bigd1 | 7,159 | 15th August 2009 - 11:08 AM Last post by: The_Fury |
|||
![]() |
18 | knight17 | 6,191 | 10th August 2009 - 05:29 AM Last post by: iG-Helping |
|||
![]() |
1 | khan4lyfe | 57 | 29th July 2009 - 09:46 PM Last post by: tansqrx |
|||
|
Lo-Fi Version | Time is now: 8th November 2009 - 07:22 PM |
© 2009 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






