troubleshooting Question

need help debugging this prob

Avatar of hawkm
hawkm asked on
C#
2 Comments1 Solution233 ViewsLast Modified:
Hi,

What my program is supposed to do is to accept a sentence and then let the user determine how many characters in each line should there be(including blank spaces). For example, if i enter:
text: Today is beautiful, enjoy it to the fullest.
width: 10
output:

Today is b
eautiful,
enjoy it t
o the full
est.

But at the moment, my program only displays 2 lines of text. eg:

Today is b
eautiful,

How do i make it to print all the entered text in the array based on the width entered like the example above.

Thanks a lot.

/////////////////////////////////////////////////////////

#include<stdio.h>
#include<string.h>

main() {

 char str[100];
 int j = 0;
 int width = 0;
 int i = 0;
 int n = 0;
 int m;

    printf("Enter Text:");
    gets(str);
    printf("Enter width for text:");
    scanf("%d",&width);

    for(i=0; i < width; i++){
   
       printf("%c",str[i]);

    }

      printf("\n");

      m = width * 2;

      for(j= width ; j < m; j++){

      printf("%c",str[j]);

     }


 return 0;

}
ASKER CERTIFIED SOLUTION
Aibras

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros