User inputs a word. Then my code finds a length of the word and after that compare letters of the word by setting a pointer to the beginning and the end of the word. It starts to increment "beginning pointer" and decrement "end pointer" and compare letters in the loop. My problem is that how to assign pointer to the letter in the beginning and in the end of the word??? I try to assign a pointer to the word. And after printf it gives me a number.....I think its an address of the word or smth..This is my code....
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(int argc, char *argv[]){
int count,i;
char *beginner_pointer;
char *ending_pointer;
//printf("This program was called with \"%s\".\n",argv[0]);
if (argc > 1){
for (count=1; count<argc; count++){
// printf("argv[%d]=%s\n", count, argv[count]);
int length = strlen(argv[count]);
beginner_pointer = argv[count];
printf("%d\n", *beginner_pointer);
}
}
//int length = strlen(argv[1]);
//printf("%d", length);
return 0;
}
beginner_pointer = argv[count];
ending_pointer = beginner_pointer + length - 1;
#include <stdio.h>
#include <string.h> // required for strlen()
int main(void) {
char *p1, *p2; // declare two char pointer
char *s = "EVITATIVE"; // this is our string
int sl = strlen(s); // returns the length of the string, requires string.h
p1 = s; // p1 points to the first letter of s
p2 = s+sl-1; // p2 points to the last letter of s, -1 because of \0
printf("%c\n", *p1); // prints the first letter
printf("%c\n", *p2); // prints the last letter
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.