C or C++. How to compare two strings given char * pointers?

前端 未结 8 1372
南笙
南笙 2020-12-07 01:01

I am sorting my array of car two ways. one by year which is shown below. and another one by make. Make is a char* How do I compare strings when I just have pointers to the

8条回答
  •  再見小時候
    2020-12-07 02:02

    In pretty much either one, the way is to call strcmp. If your strings (for some weird reason) aren't NUL terminated, you should use strncmp instead.

    However, in C++ you really shouldn't be manipulating strings in char arrays if you can reasonably avoid it. Use std::string instead.

提交回复
热议问题