0

I have an array of strings that I would like to print. I know to print them you use %s and for instance %.6s to specify printing 6 elements of string. Is there any way so that I can specify a non-fixed integer value of times to print? (For instance have it print i times in the below example). Below is my loop as is currently done.

for (i=0;i<num_locations;i++){
    printf("%.6s",&locations[i][0]);        
}
1

1 Answer 1

2

You can use * to pass a nonconstant argument: printf("%.*s", width, str);.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.