badmaash
badmaash

Reputation: 4845

sorting character array using sort()

I am trying to sort char array like this:

#include<algorithm>
...
char x[] = "coast";
sort(x, x+5);
std::cout<<x;

But it displays garbage. Integer arrays are sorted properly however.

Upvotes: 1

Views: 937

Answers (1)

ismail
ismail

Reputation: 47612

Works fine over here

[~]> clang++ test.cpp
[~]> ./a.out 
acost

Upvotes: 3

Related Questions