Nov 8, 2009

Can Anyone Solve This Question In C Programming Language?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming

Can Anyone Solve This Question In C Programming Language?

Stella Richards
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.


Comment/Reply (w/o sign-up)

PureHeart
Hi Stella,

Just a quick question about your problem. Is "x" a string or a character?

QUOTE (Stella Richards @ May 4 2009, 02:52 PM) *
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.


Comment/Reply (w/o sign-up)

magiccode9
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;
}

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords :

  1. Introduction To Programming
    (3)
  2. A Few Thoughts On Freelance Programming
    Some things I've learned along the way. (9)
    I've been freelancing my PHP / Web skills for about 8 months now. It seems like every job I
    have taken is always much larger than I planned on. About 4 months ago, I answered an ad for Joomla
    Tutoring! I get to the website, take a look around and realize that something is very wrong... The
    individual that hired me to be a tutor had hired another developer to set up the new Joomla based
    site and create a new template for it. Generally speaking, if you are really good at HTML and CSS,
    you can create a Joomla template with very little PHP knowledge. At first I was....
  3. Programming C In Windows
    2 questions (10)
    Ok I usually would use Linux to program because there is a compiler (gcc), but I need to use Windows
    to program for now because of a few unexplained reasons. I need to find a compiler for Windows that
    will compile the C language. I have tried Microsoft Visual C++ Express 2008 but I find it to be way
    too bulky and hard to use. The command-line compiler is similar to gcc I guess, and it creates
    executable files for Windows, but the compiler in the actual program compiles C++ but not C for some
    reason. And it will only compile files in projects, not standalone files. In my....
  4. What Books/e-books/articles Would You Guys Recommend For Beginners To Programming?
    (1)
    I'm looking to become somewhat knowledgeable in the area of programing one day and would like to
    know what some of you "experts" recommend as far as good reads on the subject for beginners.
    Thanks.....
  5. Please Help Me Out In Qt Programming In Linux
    (2)
    ppl, i need ur help,.... i have a project to do... we decided on Qt but no1 in my group knows about
    it... so please ppl can u find project sources ot even tutorials... Actually i m doin a proj on
    library management so if u can help even in just basic layout n connection wid forms... you can
    even contact me @ whihathac_AT_hotmail_DOT_com....
  6. How Long Have You Been Programming ?
    (101)
    Lets start this thread and find out more about our coding roadmap! The first code I ever wrote was
    on a BBC Micro Computer that came with its on embedded ROM-OS and ROM-BASIC - this was when I was in
    my 5th grade (1990-91). It was pretty powerful for those times, offering decent 16-color graphics
    and a powerful sound engine behind it (using normal computer speakers) - that PCs never achieved.
    In about an year or so, I shifted over to PCs coz the lack of applications for the BBC Micro was
    getting to me (all appz for it had to be either written in Assembly or that ROM ....

    1. Looking for Can, Anyone, Solve, This, Question, In, C, Programming, Language?

See Also,

*SIMILAR VIDEOS*
Searching Video's for Can, Anyone, Solve, This, Question, In, C, Programming, Language?
advertisement



Can Anyone Solve This Question In C Programming Language?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com