How I can solve a problem with strings ?

Dec 18th, 2013
SoccerBoss
Category:
Programming
Price: $5 USD

Question description

I’m learning C in college and when I’m exercising, I stumbled on this task, and it is a problem for me.

Numbers are saved in string, but there are no spaces between them. In order to establish which are this numbers, at the end of the string is information about the number of digits of each number and this information is separated by ”?” …. For example, a valid input string could be 125321?213. Write a procedure int SumNumb (char * str) which finds the sum of the numbers that are written in the string. If the input string is: 125321?213 function should return 12 + 5 + 213 = 230 Formatted file "Strings.txt" contains number of strings, and each of these strings are on a separate line. Example of file: 1010?22 125321?213 1545?4 Note. Considered to be in the file in one line can be most to one hundred characters. How I can solve this problem?

I've started something like that:

<code>intSumNumb(char* str){FILE* f;int br=0;
    f=fopen(str,"r");

int* a[100];

 int* b[100]; 

char c;

 int i=0; 

while(!feof(f)){
        fscanf(f,"%d%[^?]",&a[i]);
        fscanf(f,"%*c%d",&b[i]);
        i=i+1;
        br++;}

for(i=0;i<br;i++){
        printf("%d/",&a[i]);
        printf("%d",&b[i]);
        printf("/n");}}</code>

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: New York University
PREMIUM TUTOR

Studypool has helped 1,244,100 students

8 Reviews


Summary
Quality
Communication
On Time
Value
tinytim47
Dec 4th, 2016
" Wow this is really good.... didn't expect it. Sweet!!!! "
Five Star Tutor
Nov 22nd, 2016
" Outstanding Job!!!! "
mixedballz
Nov 21st, 2016
" excellent work as always thanks for the help "
lilmoe415
Nov 12th, 2016
" Thank you, Thank you, for top quality work, this is your guy!! "
darnay
Oct 29th, 2016
" The best tutor out there!!!! "
dontuwannaknow
Oct 20th, 2016
" Excellent work as always thanks so much "
SjSurvivor143
Oct 7th, 2016
" Thanks for the help. "
Joemoe
Sep 23rd, 2016
" <3 it, thanks for saving me time. "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1830 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors