Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to use printf with format from a string and numbers for string offset in C

1 Answer

0 votes
#include <stdio.h>

int main(int argc, char **argv)
{ 
	char format[] = "%d %c\n", s[] = "abcdefgh"; 
	
	printf(format, 0[s], 1[s + 4]); 
	printf(format, 0[s], 2[s + 4]); 
	printf(format, 1[s], 3[s + 4]); 
	printf(format, 1[s], 3[s + 3]); 
	
	printf("%d %c\n", *(0 + "abcdefgh"), *(1 + "abcdefgh" + 4));
	printf("%d %c\n", *(0 + "abcdefgh"), *(2 + "abcdefgh" + 4));
	printf("%d %c\n", *(1 + "abcdefgh"), *(3 + "abcdefgh" + 4));
	printf("%d %c\n", *(1 + "abcdefgh"), *(3 + "abcdefgh" + 3));
	
	return 0; 
}   
 

/*
run:
 
97 f
97 g
98 h
98 g
97 f
97 g
98 h
98 g
 
*/

 



answered Jan 17, 2019 by avibootz
edited Jan 17, 2019 by avibootz

Related questions

2 answers 274 views
1 answer 94 views
1 answer 99 views
1 answer 145 views
...