🔒 Closed Help change char value

Status
Not open for further replies.

PHC- DarkSpade

Forum Veteran
PAHELP AKO GUYS!!!

#include <iostream>
#include <cstring>
using namespace std;
char *getfirstname(char*);


int main () {

char *s;
char info[]="Aguilar,Jenn";

}
char *getfirstname(const char*str)
{

}


***ANG OUTPUT PO DAPAT

STATE IS JENN

UNG NASA ARRAY PO NA "AGUILAR,JENN" TATANGGALIN NYA PO UNG SURNAME TAS
ANG IPIPRINT NYA PO IS STATE IS JENN
 
sir may bbcode tayo for codes, pakigamit nalang para malinis tingnan yung code blocks
btw, yung return ng function mo is char* i.e. a mutable pointer pero yung input is const char*. undefined behaviour yan..

loop mo yung string (using pointers), until you find the character ',' return mo yung pointer plus 1
Code:
auto p = str;
for (; *p && *p != ','; ++p);
return p+1;
* walang error checking jan or validation ng input
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 620
    Views
  • 2
    Participants
Last reply from:
nnivx

Trending Topics

Online now

Members online
927
Guests online
1,254
Total visitors
2,181

Forum statistics

Threads
2,292,966
Posts
29,080,426
Members
1,208,612
Latest member
sarahaduterte
Back
Top