Click here to Skip to main content
12,750,710 members (37,573 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void Read_str(char a[][10],int b);
void Print_str(char a[][10],int b);

int main(void) {
    int b1;
    printf("insert number of string: ");
    char a1[b1][10];
    return EXIT_SUCCESS;

void Read_str(char a[][10],int b){
    int i;
        printf("insert string%d",i+1);

void Print_str(char a[][10],int b){
    int i;
        printf("string number%d= %s\n",i+1,a[i]);

this all of cod that i wrote.get some string and print them.
please check this code.when i write this
the code work good.but when i write this
the code did not work good.for example for b1==3 the code did not work .
Posted 8-Dec-12 3:24am
Updated 8-Dec-12 5:54am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First of all, your indexing is wrong as array starts at index 0 in C. Thus i-1 should really be i.

Then &a[i-1] is not the same address as &a[i-1][10] but the same address as &a[i-1][0].

By the way any expression with i-1 is not valid when i is 0.
ho_khalaf 8-Dec-12 9:38am
i update the code i wrote it wring before.when i use this code and want to sort all string did not work good.when i use i-1 it work good.
Philippe Mori 8-Dec-12 11:34am
You have to understand that in practice since "strings" are consecutive in memory, if you add 10 to the last indice, the effect is similar to adding 1 to the first indice as each string is 10 characters long.

So to be conceptually correct, you want to point at the beginning of the string (index 0) and not the beginning of the next string (index 10).

As an analogy, if something cost 3$, you won't say it cost 2$ and 100¢...
ho_khalaf 8-Dec-12 13:14pm
thank you very much.
good luck

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100