Skip to content
EMPS intranet

Back to top
Hi!   Hi!           Start main()

Try stepping through the code


  Value and type of last evaluated expression: Address of array element: Address of array elementx:  (none)

Your browser does not support the canvas element which will make some the features unavailable.

If you are using Internet Explorer within the University of Exeter try going to the Settings menu (probably the gear shape at the top right of this page), selecting "Compatibility View settings", unchecking "Display intranet sites in Compatibility View" and reloading this page.

Code

 Header...
// Read in a line of text, looping until it has some non-spaces. // We trim the final '\n' the end of the line. // Return 1 for success, zero for failure. // Has a problem if the input is too long //
int readoneline(char line[],int maxbytes){
  ...
» while (1) { » int i; » if (fgets(line, maxbytes, stdin)==NULL) { » return 0;// Out of data } // We don't the new-line character so chop it » i=strlen(line)-1; » if (linei=='\n') linei='\0'; // Look for a non-blank character. » for (i=0; linei; ++i) if (isspace(linei)==0) { » return 1; } }
} #define N 20 int main(){
  ...
» char line[N]; » int value; » printf("Please enter the integer value\n"); » scanf("%d", &value); » printf("Now please type in the text string, spaces are allowed!\n"); » readoneline(line, N); » return 0;
}
Memory

readoneline()

132
133
134
135
line = 224
184
185
186
187
188
189
190
191
?
?
?
?
maxbytes = 20

main(): :while {...}

144
145
146
147
i = 0

readoneline(): :while {...}

144
145
146
147
i = -909704

main()

220
221
222
223
value = -143863808
224
225
226
227
228
229
230
231
line = ' ' '\0' '\0' '\0' ' ' ' ' 'W' ' '
232
233
234
235
236
237
238
239
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
240
241
242
243
' ' '\0' '\0' '\0'

NB: the actual memory address of each variable is the
address shown plus 4294057336 (0xFFF21D78).

Show Advanced options

.

Input was:

12
My name is Earl

Show output (Before looking at the output, work out what you think it put should be and see if you are right.)

Output

Please enter the integer value
Now please type in the text string, spaces are allowed!
                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Share
Back to top