मुझे पिछले कुछ घंटों में किसी समस्या पर परेशानी हो रही है, हालांकि मुझे समझ में आया। यहां मेरी परेशानी है:स्ट्रैपी के साथ char * और char [] के बीच अंतर()
void cut_str(char* entry, int offset) {
strcpy(entry, entry + offset);
}
char works[128] = "example1\0";
char* doesnt = "example2\0";
printf("output:\n");
cut_str(works, 2);
printf("%s\n", works);
cut_str(doesnt, 2);
printf("%s\n", doesnt);
// output:
// ample1
// Segmentation: fault
मुझे लगता है कि चार */char [] के बारे में कुछ महत्वपूर्ण है जो मुझे यहां नहीं मिल रहा है।
यह प्रश्न अक्सर पूछे जाते हैं। कृपया देखें, उदाहरण के लिए, http://stackoverflow.com/questions/10186765/char-array-vs-char-pointer-in-c और http://stackoverflow.com/questions/4090434/strtok-char-array-versus -char-pointer –
संभावित डुप्लिकेट [सी में [एस] और char * s के बीच क्या अंतर है?] (http://stackoverflow.com/questions/1704407/what-is-the-difference-between -char-s-and-char-s-in-c) –