How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Jerubedo Your Own Question

Jerubedo
Jerubedo, Computer Software Engineer
Category: Programming
Satisfied Customers: 146
Experience:  I specialize in Java, Java EE, PHP, mySQL, HTML5, Javascript, LifeRay Portal, CSS, eclipse, netbeans, and SVN.
25574478
Type Your Programming Question Here...
Jerubedo is online now

How to return a character in a chosen position in the string

Resolved Question:

How to return a character in a chosen position in the string for the C language.
Submitted: 2 years ago.
Category: Programming
Expert:  Jerubedo replied 2 years ago.
Jerubedo :

Hello, I can certainly help you with this. So in the C language, there is no such thing as a string per-se. Strings are actually an array of characters, so all you would need to do given the below example:

char myString[250]; //This is a string of up to 250 characters in length

myString = "Hello World";

return myString[3]; //This would return the charcter 'l'

Jerubedo :

If this has helped, please accept the answer or rate positively using the below smiley faces as that is the only way I am paid. If you need further clarification please continue the conversation below

Customer:

Is it possible to assign it to a variable?

Jerubedo :

sure, using the above example:

char myString[250]; //This is a string of up to 250 characters in length

myString = "Hello World";

char specificCharacter = myString[3]; //This would set the specificCharacter variable to 'l'

return specificCharacter; //return the character variable

Jerubedo :

Does that help?

Customer:

I'm getting an error: incompatible types in assignment of 'char' to 'char [250]'

Jerubedo :

To execute, use this:

char myString[] = "Hello World"; //This is a string of up to 250 characters in length

char specificCharacter = myString[3]; //This would set the specificCharacter variable to 'l'

return specificCharacter; //return the character variable

Customer:

I had to put curly braces around "Hello World" otherwise the compiler found an error.

Customer:

I can print out the individual character but I can't assign it to a string (char) variable.

Jerubedo :

hmm, curly braces should not have been necessary for the above. This is C and not C++ right?

Customer:

dual compiler

Jerubedo :

Ah I see. It sounds like it is compiling for C++. Is the source file you are working in saved as a .c file?

Customer:

it's .cpp...

Jerubedo :

that's C++

Jerubedo :

C needs to be .c

Customer:

but i write c and compile it and it runs on other ppls machines that are c only

Customer:

but i'll try c only compiler...

Customer:

thanks for your help, very satisfied and i'll leave an excellent rating

Jerubedo :

any time. Let me know if you need more help after trying the c compiler only. We can continue chatting even after you rate

Customer:

ok

Customer:

yes, it's working, thank you very much

Jerubedo :

great! :)

Customer:

have a good day

Jerubedo :

you as well

Customer:

:D

Jerubedo, Computer Software Engineer
Category: Programming
Satisfied Customers: 146
Experience: I specialize in Java, Java EE, PHP, mySQL, HTML5, Javascript, LifeRay Portal, CSS, eclipse, netbeans, and SVN.
Jerubedo and 2 other Programming Specialists are ready to help you

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
< Previous | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.
 
 
 

Meet The Experts:

 
 
 
  • ATLPROG

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7260
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Previous | Next >
  • http://ww2.justanswer.co.uk/uploads/SP/spatlanta2010/2011-6-23_12450_photo.64x64.gif ATLPROG's Avatar

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7260
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
  • http://ww2.justanswer.co.uk/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Computer Software Engineer

    Satisfied Customers:

    5514
    Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
  • http://ww2.justanswer.co.uk/uploads/lifesaver333/2010-10-17_191349_ls.jpeg lifesaver's Avatar

    lifesaver

    Computer Software Engineer

    Satisfied Customers:

    936
    Several years of intensive programming and application development experience in various platforms.
  • http://ww2.justanswer.co.uk/uploads/EH/ehabtutor/2012-8-2_202016_1.64x64.jpg ehabtutor's Avatar

    ehabtutor

    Computer Software Engineer

    Satisfied Customers:

    766
    Bachelor of computer science, 5+ years experience in software development, software company owner
  • http://ww2.justanswer.co.uk/uploads/eljonis/2010-01-06_130406_eljon2.jpg Eljon's Avatar

    Eljon

    Consultant

    Satisfied Customers:

    558
    Founder of StockCanvas.com
  • http://ww2.justanswer.co.uk/uploads/FA/fael/2011-1-15_104041_profile500x500.64x64.jpg Rafael Martins's Avatar

    Rafael Martins

    Computer Software Engineer

    Satisfied Customers:

    446
    Desktop, Mobile and Web Developer. 7+ years of experience. Creative solutions provider.
  • http://ww2.justanswer.co.uk/uploads/CH/chutz747/2011-11-6_14231_me.64x64.jpg The-PC-Guy's Avatar

    The-PC-Guy

    Software Engineer

    Satisfied Customers:

    325
    Extensive Knowledge in PHP, MYSQL, CSS & Javascript
 
 
 

Related Programming Questions